J
John Galenski
I'm trying to group and count information based on the following XML:
<Report>
<Record>
<Id>1</Id>
<Status>
<![CDATA[ Unreviewed ]]>
</Status>
<Component>
<![CDATA[ Sales ]]>
</Component>
</Record>
<Record>
<Id>2</Id>
<Status>
<![CDATA[ To Do ]]>
</Status>
<Component>
<![CDATA[ Training ]]>
</Component>
</Record>
...
</Report>
The output would look something like this:
Unreviewed: 5
Sales: 4
Training: 1
To Do: 3
Sales: 2
Training: 1
I'm grouping ok, but cannot figure out how to count be each area. Here's a
snippet of the XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="recs-by-status" match="Report/Record" use="Status" />
<xsl:template match="/">
<xsl:for-each select="Report/Record[count(. | key('recs-by-status',
Status)[1]) = 1]">
<xsl:sort select="Status" />
<xsl:value-of select="Status" /> = <xsl:value-of
select="count(key('recs-by-status', Status))"/><br />
Sales: <xsl:value-of
select="count(Report/Record[Component='Sales'][Status=key('recs-by-status',
Status)])"/><br />
Training: xsl:value-of
select="count(Report/Record[Component='Training'][Status=key('recs-by-status',
Status)])"/><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I'm trying to avoid having another for-each statement if that's at all
possible. Any pointers would be appreciated.
Thanks,
John G.
<Report>
<Record>
<Id>1</Id>
<Status>
<![CDATA[ Unreviewed ]]>
</Status>
<Component>
<![CDATA[ Sales ]]>
</Component>
</Record>
<Record>
<Id>2</Id>
<Status>
<![CDATA[ To Do ]]>
</Status>
<Component>
<![CDATA[ Training ]]>
</Component>
</Record>
...
</Report>
The output would look something like this:
Unreviewed: 5
Sales: 4
Training: 1
To Do: 3
Sales: 2
Training: 1
I'm grouping ok, but cannot figure out how to count be each area. Here's a
snippet of the XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="recs-by-status" match="Report/Record" use="Status" />
<xsl:template match="/">
<xsl:for-each select="Report/Record[count(. | key('recs-by-status',
Status)[1]) = 1]">
<xsl:sort select="Status" />
<xsl:value-of select="Status" /> = <xsl:value-of
select="count(key('recs-by-status', Status))"/><br />
Sales: <xsl:value-of
select="count(Report/Record[Component='Sales'][Status=key('recs-by-status',
Status)])"/><br />
Training: xsl:value-of
select="count(Report/Record[Component='Training'][Status=key('recs-by-status',
Status)])"/><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I'm trying to avoid having another for-each statement if that's at all
possible. Any pointers would be appreciated.
Thanks,
John G.