Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: msxml-node-set >Thread Next - Re: msxml-node-set Re: msxml-node-setTo: 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><gods> <god>Kibo</god> <god>Xibo</god> </gods></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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
