Re: [xsl] Recursively Merging 2 XML files with XSLT

Subject: Re: [xsl] Recursively Merging 2 XML files with XSLT
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 23 Nov 2006 12:16:02 GMT
If your two files are ad1.xml and ad2.xml, and they really have the same
structure, then something like this:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:variable name="a" select="document('ad1.xml')//data"/>
<xsl:variable name="b" select="document('ad2.xml')//data"/>

<xsl:template match="/">
  <html>
    <head>
    </head>
    <body>
      <table>
	<xsl:for-each select="$a">
	  <xsl:variable name="p" select="position()"/>
	  <tr>
	    <td><xsl:value-of select="@val"/></td>
	    <td><xsl:value-of select="$b[$p]/@val"/></td>
	  </tr>
	</xsl:for-each>
      </table>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>



$ saxon ad.xsl ad.xsl
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   </head>
   <body>
      <table>
         <tr>
            <td>xx</td>
            <td>xx</td>
         </tr>
         <tr>
            <td>yy</td>
            <td>yy2</td>
         </tr>
         <tr>
            <td>ss</td>
            <td>ss</td>
         </tr>
         <tr>
            <td>gg</td>
            <td>gg2</td>
         </tr>
      </table>
   </body>
</html>

Current Thread