Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: msxml-node-set

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 11/4/2005 6:00:00 PM

Igor Milavec wrote:

> "Martin Honnen" wrote:
> 
>>You seem to want to parse that text inside of <USERS> into nodes but 
>>within XPath 1.0/XSLT 1.0 there is no way to do that unless your XSLT 
>>stylesheet tries to use XPath string processing to parse such text and 
>>create nodes as needed.
> 
> 
> do you know if there is a private extension in MSXML or .NET that 
> would support such dynamic parsing?

Both XSLT processors (MSXML, .NET) allow to add extension objects or 
script functions, here is an example with MSXML and JScript where an 
extension function in JScript takes a string with XML markup as the 
argument to create an MSXML DOMDocument, parse that string and return 
the document to XSLT where it can be treated as a node set. In that 
example the root element of the parsed document is used in the select 
attribute of an xsl:apply-templates and that stylesheet then simply 
applies the identity transformation to demonstrate that the return nodes 
can be processed with XSLT/XPath.

XML test document is

<?xml version="1.0" encoding="UTF-8"?>
<exampleMarkup>&lt;gods&gt;
   &lt;god&gt;Kibo&lt;/god&gt;
   &lt;god&gt;Xibo&lt;/god&gt;
&lt;/gods&gt;</exampleMarkup>

The stylesheet is

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:msxsl="urn:schemas-microsoft-com:xslt"
   xmlns:ps="http://example.com/2005/msxmlParser"
   version="1.0">

<xsl:output method="xml" indent="yes" />

<msxsl:script language="JScript" implements-prefix="ps">
<![CDATA[
function parseIntoDocument (xmlMarkup, msxmlVersion) {
   var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.' + 
msxmlVersion + '.0');
   xmlDocument.async = false;
   xmlDocument.loadXML(xmlMarkup);
   return xmlDocument;
}
]]>
</msxsl:script>

<xsl:template match="/">
   <results>
     <xsl:apply-templates 
select="ps:parseIntoDocument(string(exampleMarkup), 
system-property('msxsl:version'))/*" />
   </results>
</xsl:template>

<xsl:template match="@* | * | comment() | processing-instruction() | 
text()">
   <xsl:copy>
     <xsl:apply-templates select="@* | node()" />
   </xsl:copy>
</xsl:template>

</xsl:stylesheet>

The output when I run that with MSXML 4 is

<?xml version="1.0"?>
<results xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:ps="http://example.com/2005/msxmlParser">
<gods>
<god>Kibo</god>
<god>Xibo</god>
</gods>
</results>

Of course in reality you need to decide on some strategy what to return 
from that script function if parsing of the markup passed in fails.

And I don't remember what the original request was, my example assumes 
well-formed markup with a root element is passed to that function, 
depending on your needs if you want to pass fragments of XML to that 
function and parse that then you would need to wrap the string into some 
root element markup e.g.

function parseIntoDocument (xmlMarkup, msxmlVersion) {
   var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.' + 
msxmlVersion + '.0');
   xmlDocument.async = false;
   xmlDocument.loadXML('<myroot>' + xmlMarkup + '</myroot>');
   return xmlDocument;
}


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent