I wanted to pull several XML docs into one XSLT stylesheet, that would then be transformed to XHTML using the transformNode method within an ASPX doc, and I came up with 2 great solutions after reading several articles:
Method #1
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" encoding="UTF-8" indent="yes"/>
<xsl:variable name="doc1" select="document('http://SERVER/DIRECTORY/docs/xml/testdoc1.xml')" />
<xsl:variable name="doc2" select="document('http://SERVER/DIRECTORY/docs/xml/testdoc2.xml')" />
<xsl:template match="/">
Method #1:<br />
<xsl:for-each select="$doc1">
<xsl:value-of select="home/header/seal_url"/>
</xsl:for-each>
<br /><br />
<xsl:for-each select="$doc2">
<xsl:value-of select="home/alert/alert_title"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Method #2
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
Method #2:<br />
<xsl:for-each select="document('http://SERVER/DIRECTORY/docs/xml/testdoc1.xml')">
<xsl:value-of select="home/header/seal_url" />
</xsl:for-each>
<br /><br />
<xsl:for-each select="document('http://SERVER/DIRECTORY/docs/xml/testdoc2.xml')">
<xsl:value-of select="home/alert/alert_title" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
But both of these solutions require that the root elements' name be identical.
So now I'd like to know if it's possible to have 2 or more XML doc's with different root element names, like this:
xmldoc1.xml
<doc1>
<something>
<moreinfo>...</moreinfo>
</something>
</doc1>
xmldoc2.xml
<doc2>
<yadayada>
<whatever>...</whatever>
</yadayada>
</doc2>
...and then combine them into one, which would result in this output:
<combined>
<doc1>
<something>
<moreinfo>...</moreinfo>
</something>
</doc1>
<doc2>
<yadayada>
<whatever>...</whatever>
</yadayada>
</doc2>
</combined>
Thanks.
KWilliams