I am new to XSL and in the process of picking this up from scratch to solve a problem.
I have a source XML file that contains the following structure:-
<root>
<Header>
</Header>
<DetailRecord>
<CustomerNumber>1</CustomerNumber>
<DetailSubRecord>
<Address>London</Address>
</DetailSubRecord>
<DetailSubRecord>
<Address>Hull</Address>
</DetailSubRecord>
</DetailRecord>
<DetailRecord>
<CustomerNumber>2</CustomerNumber>
<DetailSubRecord>
<Address>Birmingham</Address>
</DetailSubRecord>
<DetailSubRecord>
<Address>Manchester</Address>
</DetailSubRecord>
</DetailRecord>
<Footer>
</Footer>
</root>
where there are mutiple <DetailRecord>
s each with multiple <DetailSubRecord>
s.
I have managed to put together an XSL that outputs a single nested set of multiple DetailRecords to a flat file but I haven't been able to puzzle out how to refer to the 2nd nested level of address records in the XSL...
Here is my XSL so far:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="text"/>
<xsl:variable name="spaces" select="' '"/>
<xsl:variable name="newline">
<xsl:text> </xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="root/Header/HeaderField"/>
<xsl:copy-of select="$newline"/>
<xsl:for-each select="root/DetailRecord">
<xsl:value-of select="CustomerNumber"/>
<xsl:copy-of select="$newline"/>
</xsl:for-each>
Trailer - recordCount - <xsl:value-of select="count(root/DetailRecord)"/>
</xsl:template>
</xsl:stylesheet>