This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Acheiving ..2nd level grouping but with different node structure ..
- From: "G. Ken Holman" <gkholman at CraneSoftwrights dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 24 Jul 2002 10:02:03 -0400
- Subject: Re: [xsl] Acheiving ..2nd level grouping but with different node structure ..
- Reply-to: xsl-list at lists dot mulberrytech dot com
At 2002-07-24 08:59 -0400, KUMAR NINGASHETTY wrote:
This seemed little different having different parent nodes for 2nd
level grouping using keys ..
Sometimes using keys isn't always the easiest for multiple-level grouping.
Consider the solution below that doesn't use keys at all, but uses
variables instead.
I hope this helps.
................ Ken
Here is my XSL with first level grouping extracting distinct
regions and i am having problems grouping users within Region .
Any help appreciated .
T:\ftemp>type kumar.xml
<rep>
<uwr>
<los userid="1014" reg="Region 4">
<review type="N"><![CDATA[11]]></review>
<review type="Y"><![CDATA[16]]></review>
</los>
<los userid="1017" reg="Region 4">
<review type="N"><![CDATA[7]]></review>
<review type="Y"><![CDATA[17]]></review>
</los>
<los userid="1025" reg="Region 2">
<review type="N"><![CDATA[13]]></review>
<review type="Y"><![CDATA[12]]></review>
</los>
</uwr>
<arr>
<los userid="1014" reg="Region 4">
<review type="N"><![CDATA[15]]></review>
<review type="Y"><![CDATA[19]]></review>
</los>
<los userid="1017" reg="Region 4">
<review type="N"><![CDATA[20]]></review>
<review type="Y"><![CDATA[22]]></review>
</los>
<los userid="1025" reg="Region 2">
<review type="N"><![CDATA[23]]></review>
<review type="Y"><![CDATA[25]]></review>
</los>
</arr>
</rep>
T:\ftemp>type kumar.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="los" select="/*/*/los"/>
<xsl:for-each select="$los">
<xsl:if test="generate-id(.)=
generate-id($los[@reg=current()/@reg])">
<xsl:text>
</xsl:text>
<xsl:value-of select="@reg"/>
Userid UWR(n) UWR(Y) ARR(N) ARR(Y)
<xsl:variable name="regs" select="$los[@reg=current()/@reg]"/>
<xsl:for-each select="$regs">
<xsl:if test="generate-id(.)=
generate-id($regs[@userid=current()/@userid])">
<xsl:text> </xsl:text>
<xsl:value-of select="@userid"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="/rep/uwr/los[@userid=current()/@userid]/review[@type='N']"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="/rep/uwr/los[@userid=current()/@userid]/review[@type='Y']"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="/rep/arr/los[@userid=current()/@userid]/review[@type='N']"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="/rep/arr/los[@userid=current()/@userid]/review[@type='Y']"/>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
T:\ftemp>xt kumar.xml kumar.xsl
Region 4
Userid UWR(n) UWR(Y) ARR(N) ARR(Y)
1014 11 16 15 19
1017 7 17 20 22
Region 2
Userid UWR(n) UWR(Y) ARR(N) ARR(Y)
1025 13 12 23 25
T:\ftemp>rem Done!
--
Upcoming hands-on in-depth 3-days XSLT/XPath and/or 2-days XSL-FO:
North America: Sep 30-Oct 4,2002
Japan: Oct 7-Oct 11,2002
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6 Definitive XSLT and XPath
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1 Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed),
articles, training (instructor-live,Internet-live,web/CD,licensed)
Next public training: 2002-08-05,26,27,09-30,10-03,07,10
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list