xslt grouping with attributes
Got the following XML
<?xml version='1.0' encoding='iso-8859-1' ?>
<?xml-stylesheet type='text/xsl' href='piv.xsl'?>
<all>
<h m='1' n='a'>51</h>
<h m='2' n='a'>6</h>
<h m='3' n='a'>7</h>
<h m='4' n='a'>8</h>
<h m='1' n='b'>52</h>
<h m='3' n='b'>5</h>
<h m='1' n='c'>53</h>
<h m='2' n='c'>5</h>
<h m='3' n='c'>5</h>
<h m='4' n='c'>5</h>
<h m='5' n='c'>5</h>
<h m='1' n='d'>54</h>
<h m='2' n='d'>5</h>
<h m='3' n='d'>5</h>
<h m='4' n='d'>5</h>
<h m='1' n='e'>55</h>
<h m='2' n='e'>5</h>
<h m='3' n='e'>5</h>
</all>
and wish to diplay as crosstab, using @m and @n
however in process I've got this xslt
<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:preserve-space elements="*"/>
<xsl:output method="html" />
<xsl:key name="tw-key" match="h" use="@n" />
<xsl:key name="month-key" match="h" use="@m" />
<xsl:variable name = "tw_names" select="//h[generate-id()=generate-id(key('tw-key',@n)[1])]/@n"/>
<xsl:variable name = "month_names" select="//h[generate-id()=generate-id(key('month-key',@m)[1])]/@m"/>
<xsl:template match="/">
<html>
<title>Test</title>
<body>
<xsl:apply-templates mode="d0a"/>
</body>
</html>
</xsl:template>
<xsl:template match="all" mode = 'd0a'>
template d0
<table>
<xsl:for-each select ="$tw_names">
<xsl:sort select="$tw_names"/>
<xsl:for-each select ="$month_names">
<xsl:sort select="$month_names"/>
<tr><td align='right'>- month:</td>
<td> <xsl:value-of select="$month_names[//@m=current()]"/> </td>
<td></td>
<td><xsl:value-of select="@m"/></td>
<td><xsl:value-of select="format-number(sum(h),'#,##0')"/></td>
</tr>
</xsl:for-each>
<tr><td> name:</td>
<td>xx- <xsl:value-of select="$tw_names[//@n=current()]"/> -xx</td>
<td></td>
<td><xsl:value-of select="@m"/></td>
<td><xsl:value-of select="format-number(sum(h),'#,##0')"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
and it instead of giving me
- month: 1 0
- month: 2 0
- month: 3 0
- month: 4 0
name: a 0
- month: 1 0
- month: 3 0
name: b 0
- month: 3 0
- month: 4 0
- month: 5 0
name: c 0
- month: 1 0
- month: 2 0
- month: 3 0
- month: 4 0
name: d 0
- month: 1 0
- month: 2 0
- month: 3 0
name: e 0
its just giving me
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
name: a 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
name: a 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
name: a 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
name: a 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
- month: 1 0
name: a 0
Help .. I've been stuck for yonks now!
|