![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Merging node-sets in XSL Re: Merging node-sets in XSLTo: NULL Date: 12/26/2007 1:50:00 PM barnum@b... wrote: > Is there any easy way to do this in XSL? With XSLT 1.0 you could either chain two transformations or make use of an extension function to convert a result tree fragment into a node-set: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="by-name" match="fruits/*" use="name()"/> <xsl:variable name="merger"> <fruits> <xsl:copy-of select="fruits/*"/> <xsl:copy-of select="document('test2007122603.xml')/fruits/*"/> </fruits> </xsl:variable> <xsl:template match="fruits"> <xsl:copy> <xsl:copy-of select="exsl:node-set($merger)/fruits/*[generate-id() = generate-id(key('by-name', name())[1])]"/> </xsl:copy> </xsl:template> </xsl:stylesheet> That stylesheet works fine for me for your XML sample documents and XslCompiledTransform in .NET 2.0 or Saxon 6.5.5. The "master" document is the primary XML input document, the other document is loaded with the document('test2007122603.xml'). For MSXML you need to change the namespace of the extension function to urn:schemas-microsoft-com:xslt: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="by-name" match="fruits/*" use="name()"/> <xsl:variable name="merger"> <fruits> <xsl:copy-of select="fruits/*"/> <xsl:copy-of select="document('test2007122603.xml')/fruits/*"/> </fruits> </xsl:variable> <xsl:template match="fruits"> <xsl:copy> <xsl:copy-of select="msxsl:node-set($merger)/fruits/*[generate-id() = generate-id(key('by-name', name())[1])]"/> </xsl:copy> </xsl:template> </xsl:stylesheet> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
