This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: RE: grouping content
- To: "Jeni Tennison" <mail at jenitennison dot com>, <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Re: RE: grouping content
- From: "Yang" <sfyang at unisvr dot net dot tw>
- Date: Mon, 9 Apr 2001 09:05:19 +0800
- Cc: <GavinM at yatra dot net>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi,
Once again, Jeni presented a complete and clear description how to work out
the grouping problem using xslt.
In this presentation, I would like to point out there are some typo errors
in missing sign of **)** with concat function and one in using
LocationGroups key name
which is another typo error of **locs-by-area**.
Following is a complete list of using apply-templates styles for a reference
which has been tested using msxml3.
Hopefully it helps newbies easily to learn Jeni's technique to solve
grouping problems.
** Group-content.xsl **
<?xml version="1.0" encoding="iso-8859-1" ?>
- <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="locs-by-area" match="Location" use="@Area" />
<xsl:key name="locs-by-area-and-type" match="Location" use="concat(@Area,
':', @Type)" />
- <xsl:template match="/">
<xsl:apply-templates select="//US" />
</xsl:template>
+ <xsl:template match="US">
- <!-- iterate over the Location elements with unique Areas
-->
<xsl:apply-templates mode="area-group" select="Location[generate-id()
=generate-id(key('locs-by-area', @Area)[1])]" />
</xsl:template>
- <xsl:template match="Location" mode="area-group">
- <!-- output a line giving the Area
-->
<xsl:value-of select="@Area" />
<br />
<br />
- <!--
iterate over the Location elements with this Area, but only
those with unique Types
-->
<xsl:apply-templates mode="area-and-type-group"
select="key('locs-by-area', @Area)[generate-id()
= generate-id(key('locs-by-area-and-type', concat(@Area, ':', @Type))[1])]"
/>
</xsl:template>
- <xsl:template match="Location" mode="area-and-type-group">
- <!-- output a line giving the Type
-->
<xsl:value-of select="@Type" />
<br />
- <!--
create a variable to hold the Locations with that Type
in that Area
-->
<xsl:variable name="locations" select="key('locs-by-area-and-type',
concat(@Area, ':', @Type))" />
- <!-- apply templates to the location with Rural scope
-->
<xsl:apply-templates select="$locations[@Scope = 'Rural']" />
- <!-- apply templates to the location with Urban scope
-->
<xsl:apply-templates select="$locations[@Scope = 'Urban']" />
</xsl:template>
- <xsl:template match="Location">
<xsl:value-of select="@Scope" />
:
<xsl:value-of select="@value" />
<br />
</xsl:template>
</xsl:stylesheet>
Sun-fu Yang
sfyang@unisvr.net.tw
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list