I have two files.
Content of f1 is:
<applianceVersion>
<id>main</id>
<version>0301</version>
<components>
<component>
<id>A</id>
<version>a1</version>
</component>
<component>
<id>B</id>
<version>b1</version>
</component>
<component>
<id>C</id>
<version>c1</version>
</component>
</components>
</applianceVersion>
Content of f2 is:
<applianceVersion>
<id>main</id>
<version>0301</version>
<components>
<component>
<id>A</id>
<version>a2</version>
</component>
<component>
<id>B</id>
<version>b2</version>
</component>
<component>
<id>C</id>
<version>c3</version>
</component>
</components>
</applianceVersion>
The two files will always have the same components. My goal is to show both content side by side like the following:
main 0301 0302
A a1 a2
B b1 b2
C c1 c2
I have the following xsl applied to f1:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="1">
<tr bgcolor="#87E0F8">
<th style="text-align:left"><xsl:value-of select="applianceVersion/id"/></th>
<th style="text-align:left"><xsl:value-of select="applianceVersion/version"/></th>
<th style="text-align:left"><xsl:value-of select="document('f2.xml')/applianceVersion/version"/></th>
</tr>
<tr>
</tr>
<xsl:for-each select="applianceVersion/components/component">
<tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="version"/></td>
<xsl:for-each select="document('f2.xml')/applianceVersion/components/component[id=<xsl:value-of select="id"/>]">
<td><xsl:value-of select="version"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
I am a newbie to xslt.. And the above code is erroring out.
So the questions are:
- How do I reference "id" within the for-each filter to take up different value?
- Is there a better way to accomplish the same?