I'm trying to work out how to use XSL to group an XML by the tag . Basically I want all the records to output the A's first, then the B's, then the C's if they existed which they don't in this example.
<PAYSLIP>
<RECORD.MISC>
<EMP_ID>0009011</EMP_ID>
<ITEM.MISC>
<ID>1001</ID>
<DESCRIPTION>First Job Pay</DESCRIPTION>
<VALUE>1000</VALUE>
<SOURCE>A</SOURCE>
</ITEM.MISC>
<ITEM.MISC>
<ID>1001</ID>
<DESCRIPTION>Second Job Pay</DESCRIPTION>
<VALUE>500</VALUE>
<SOURCE>B</SOURCE>
</ITEM.MISC>
<ITEM.MISC>
<ID>1001</ID>
<DESCRIPTION>Car Allowance</DESCRIPTION>
<VALUE>50</VALUE>
<SOURCE>A</SOURCE>
</ITEM.MISC>
</RECORD.MISC>
</PAYSLIP>
The output required is:
>A
>First Job Pay 1000
>Car Allowance 50
>B
>Second Job Pay 500
I can achieve this with the following XSL but can't work out how to use a for-each-group or key statement to do this? At present I am going to have to repeat this piece of code for each letter of the alphabet which is not very efficient so I would be keen to learn another way to do this?
<xsl:for-each select="ITEM.MISC[SOURCE='A']">
<tr><xsl:value-of select="SOURCE"/></tr>
<tr>
<td class="description">
<xsl:value-of select="DESCRIPTION"/>
</td>
<td></td>
<td class="value">
<xsl:call-template name="formatnumber">
<xsl:with-param name="value"><xsl:value-of select="VALUE"/></xsl:with-param>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
<xsl:for-each select="ITEM.MISC[SOURCE='B']">
<tr><xsl:value-of select="SOURCE"/></tr>
<tr>
<td class="description">
<xsl:value-of select="DESCRIPTION"/>
</td>
<td></td>
<td class="value">
<xsl:call-template name="formatnumber">
<xsl:with-param name="value"><xsl:value-of select="VALUE"/></xsl:with-param>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
Any help much appreciated!
No comments:
Post a Comment