This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
xsl:key and grouping
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] xsl:key and grouping
- From: Roger dot Menday at dresdnerkb dot com
- Date: Tue, 27 Feb 2001 11:08:33 -0000
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hello,
I am both new to XSL and new to this list ...
I would like to use XSL to group common elements from an XML source, in the
transformed output.
So far I have used some code found in the archives of this list.
Anyway, the example I am using to explore this stuff is as follows :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version =
"1.0" >
<xsl:key name="carkey" match="item" use="car" />
<xsl:template match = "favouritecars" >
<xsl:apply-templates select="item[ count(. | key('carkey', car)[1])=1 ]"
>
<xsl:sort select="car"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="/favouritecars/item">
<h4><xsl:value-of select="car"/></h4>
<xsl:for-each select="key('carkey', car)">
<xsl:sort select="name"/>
<xsl:apply-templates select="name"/>
</xsl:for-each> <br/><br/>
</xsl:template>
<xsl:template match="/favouritecars/item/name">
<xsl:value-of select="."/><br/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="ISO-8859-1"?>
<favouritecars>
<item>
<name>Mary</name>
<car>Mini</car>
<car>Fiesta</car>
<car>Metro</car>
</item>
<item>
<name>Neil</name>
<car>Fiesta</car>
</item>
<item>
<name>Peter</name>
<car>Escort</car>
</item>
</favouritecars>
I wish to order the information via car, rather than person. This all works
fine until I give a particular person
more than one favourite car element, which either the xsl:key doesn't pick
up, or that I don't use when accessing the key.
i.e. in the example above the transformed xml fails to pick up the all the
cars.
Well, something definately is not quite right.
... my failure to correct it, I guess displays my lack of deep
understanding of the
language - something I would like to acquire, as i rather like the ideas and
the language.
Anyway, can someone give me some pointers for the right way to continue ?
Roger
----------------------------------------------------------------------
If you have received this e-mail in error or wish to read our e-mail
disclaimer statement and monitoring policy, please refer to
http://www.drkw.com/disc/email/ or contact the sender.
----------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list