Discussion:
XSL Processor Add object
(too old to reply)
Praveen
2005-10-26 12:10:09 UTC
Permalink
Im using following code for xml/xsl transform using asp

set xml = Server.CreateObject("MSXML2.DOMDocument")
xml.async = false
xml.load("MyXML.xml")

set xsl=Server.CreateObject("MSXML.FreeThreadedDOMDocument")
xsl.async=false
xsl.load("MyXSL.xsl") '

set xslTemplate=Server.CreateObject("Msxml2.XSLTemplate")
set xslTemplate.stylesheet=xsl
set xslProcessor=xslTemplate.createProcessor
xslProcessor.input=xml

set Tinyxml = Server.CreateObject("MSXML.FreeThreadedDOMDocument") 'or
"MSXML2.DOMDocument"?????
Tinyxml .async = false
Tinyxml .loadXML "<Root><Item name="PQR"/><Item name="XYZ"/></</Root>"

xslProcessor.addObject Tinyxml, "urn:ABC"

xslProcessor.transform()

Response.Write(xslProcessor.output)


This code is wroking fine....

Insdie xsl Im having xmlns:PC="urn:ABC"

My question is regarding the TinyXML object which Im adding to the
xslProcessor.
If I want to Print the TinyXML as a string or read some value from TinyXML
or Loop Thru TinyXML
How it is possible.



I tried some thing like this
<xsl:value-of select="PC:get-text()"/>



I want to what type of operations can I do with the XmlObj which Im adding
to Proccessor......


thanks

praveen
Martin Honnen
2005-10-26 14:06:11 UTC
Permalink
Post by Praveen
Insdie xsl Im having xmlns:PC="urn:ABC"
My question is regarding the TinyXML object which Im adding to the
xslProcessor.
If I want to Print the TinyXML as a string or read some value from TinyXML
or Loop Thru TinyXML
I want to what type of operations can I do with the XmlObj which Im adding
to Proccessor......
You need to access properties of the objects as
prefix:get-propertyname()
e.g. if that is an XML DOMDocument object then you can do
prefix:get-xml()
to get the serialized XML markup or
prefix:get-documentElement()
to get the documentElement object (and for instance use that in an XSLT
instruction like xsl:copy-of).

Here is a complete example in JScript:

var msxmlVersion = '3.0';
var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.' + msxmlVersion);
xmlDocument.loadXML([
'<gods',
' <god>Kibo</god>',
'</gods>'
].join('\r\n'));

var xslDocument = new ActiveXObject('Msxml2.FreeThreadedDOMDocument.' +
msxmlVersion);
xslDocument.loadXML([
'<xsl:stylesheet ',
' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"',
' version="1.0"',
' xmlns:obj1="http://example.com/2005/10/ns1">',
' <xsl:output method="xml" indent="yes" />',
'',
' <xsl:template match="/">',
' <results>',
' <complete-markup>',
' <xsl:value-of select="obj1:get-xml()" />',
' </complete-markup>',
' <copy>',
' <xsl:copy-of select="obj1:get-documentElement()" />',
' </copy>',
' </results>',
' </xsl:template>',
'',
'</xsl:stylesheet>'
].join('\r\n'));

var xslTemplate = new ActiveXObject('Msxml2.XSLTemplate.' + msxmlVersion);
xslTemplate.stylesheet = xslDocument;

var xsltProcessor = xslTemplate.createProcessor();

var extensionObject = new ActiveXObject('Msxml2.DOMDocument.' +
msxmlVersion);
extensionObject.loadXML('<god>Kibo</god>');

xsltProcessor.addObject(extensionObject, 'http://example.com/2005/10/ns1');

xsltProcessor.input = xmlDocument;

xsltProcessor.transform();

xsltProcessor.output


The string output then is <?xml version="1.0" encoding="UTF-16"?> <results xmlns:obj1="http://example.com/2005/10/ns1"> <complete-markup>&lt;god&gt;Kibo&lt;/god&gt;
</complete-markup>
<copy>
<god>Kibo</god>
</copy>
</results>


Note that you can also pass in XML DOM objects as parameters to the
stylesheet.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Praveen
2005-10-27 03:52:07 UTC
Permalink
Thanks for the reply.
I want to know one more thing.
If I add 2 objects thru xsltProcessor,
One an xmlDoc and another xslDoc.

Is there any way to do transform of this inside xsl??

thanks
praveen
Post by Martin Honnen
Post by Praveen
Insdie xsl Im having xmlns:PC="urn:ABC"
My question is regarding the TinyXML object which Im adding to the
xslProcessor.
If I want to Print the TinyXML as a string or read some value from
TinyXML or Loop Thru TinyXML
I want to what type of operations can I do with the XmlObj which Im
adding to Proccessor......
You need to access properties of the objects as
prefix:get-propertyname()
e.g. if that is an XML DOMDocument object then you can do
prefix:get-xml()
to get the serialized XML markup or
prefix:get-documentElement()
to get the documentElement object (and for instance use that in an XSLT
instruction like xsl:copy-of).
var msxmlVersion = '3.0';
var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.' + msxmlVersion);
xmlDocument.loadXML([
'<gods',
' <god>Kibo</god>',
'</gods>'
].join('\r\n'));
var xslDocument = new ActiveXObject('Msxml2.FreeThreadedDOMDocument.' +
msxmlVersion);
xslDocument.loadXML([
'<xsl:stylesheet ',
' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"',
' version="1.0"',
' xmlns:obj1="http://example.com/2005/10/ns1">',
' <xsl:output method="xml" indent="yes" />',
'',
' <xsl:template match="/">',
' <results>',
' <complete-markup>',
' <xsl:value-of select="obj1:get-xml()" />',
' </complete-markup>',
' <copy>',
' <xsl:copy-of select="obj1:get-documentElement()" />',
' </copy>',
' </results>',
' </xsl:template>',
'',
'</xsl:stylesheet>'
].join('\r\n'));
var xslTemplate = new ActiveXObject('Msxml2.XSLTemplate.' + msxmlVersion);
xslTemplate.stylesheet = xslDocument;
var xsltProcessor = xslTemplate.createProcessor();
var extensionObject = new ActiveXObject('Msxml2.DOMDocument.' +
msxmlVersion);
extensionObject.loadXML('<god>Kibo</god>');
xsltProcessor.addObject(extensionObject,
'http://example.com/2005/10/ns1');
xsltProcessor.input = xmlDocument;
xsltProcessor.transform();
xsltProcessor.output
</complete-markup>
<copy>
<god>Kibo</god>
</copy>
</results>
Note that you can also pass in XML DOM objects as parameters to the
stylesheet.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Martin Honnen
2005-10-27 10:41:21 UTC
Permalink
Post by Praveen
I want to know one more thing.
If I add 2 objects thru xsltProcessor,
One an xmlDoc and another xslDoc.
Is there any way to do transform of this inside xsl??
Maybe, I would need to test that, as it is possible to call methods of
extension objects it might work to to e.g.
xmlDocPrefix:transformNode(xslDocPrefix:get-documentElement())
Whether that is helpful I am not sure, if you already have the objects
outside of the processor then you could call transformNode there outside
of the processor and if the result of that is needed for a
transformation you could pass that in.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Continue reading on narkive:
Loading...