I have an XML file that I am using XSL to convert into an html page. I would like to loop through the XML file which contains many parent nodes, and then loop through the child nodes and display the result in an HTML table.
So far I am able to loop through the Parent node and sucessful return them, but when I nest a for-each loop inside there to return the attibutes of the child node, I end up returning the attributes of all child nodes in the document and not the ones specific to the parent node.
Can anyone shed a little light on this.
XML:
<AdminReports xmlns="30/11/2011 09:25:58">
<AdminReport ID="1">
<DataSourceInformation DataSourceID="12" Value="DSI_50"/>
</AdminReport>
<AdminReport ID="2">
<DataSourceInformation DataSourceID="23" Value="DSI_30"/>
</AdminReport>
<AdminReport ID="3">
<DataSourceInformation DataSourceID="34" Value="DSI_20"/>
</AdminReport>
</AdminReports>
XSL:
<table border="1" cellspacing="2" width="800" bgcolor="white">
<xsl:for-each select="/*/*[name()='AdminReport']">
<tr bgcolor="9acd32">
<table><th>Admin Report Num:</th></table>
<table><th><xsl:value-ofselect="@ID"/> </th></table>
</tr>
<tr>
<xsl:for-each select="/*/*/*[name()='DataSourceInformation']">
<table><th>Data Report ID:</th></table>
<table><th><xsl:value-of select="@DataSourceID"/></th></table>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
You’re over-compicating this.
selectis relative to the current context node: