This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: variable handling
- From: "J.Pietschmann" <j3322ptm at yahoo dot de>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 01 Oct 2002 21:48:03 +0200
- Subject: Re: [xsl] variable handling
- References: <F161oYvslclX9QZwx7y00012ef5@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Anita Sood wrote:
I dont know what should be the appropriate title for this problem of
mine.
You appear to have a "grouping problem": You want to group
your members by team.
The usual solution is called Muenchean Grouping, described
in detail in the XSLT FAQ reachable from
http://www.mulberrytech.com/xsl/xsl-list/
and Jeni Tennisons site:
http://www.jenitennison.com/xslt/grouping/index.html
For your specific problem, define a key which identifies
the groups, in your case, the elements to match are the
rows, the group a row belongs to is identified by its
team child element:
<xsl:key name="row-by-team" match="row" use="team"/>
In some template, you select rows, but make sure to select
only the first row of each group by a special trick. This
way you actually got the groups, defined by it's first member,
and you only need to process the whole group, selected by the
key:
<xsl:template match="TeamInfo">
<teams>
<xsl:for-each select="row[generate-id()
=generate-id(key('row-by-team',team)[1])]">
<team number="{team} name="{teamName}">
<xsl:for-each select="key('row-by-team',team)">
<member><xsl:value-of select="."/></member>
</xsl:for-each>
</team>
</xsl:for-each>
</teams>
</xsl:template>
(untested)
HTH
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list