This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: grouping headers
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] grouping headers
- From: "Corey Spitzer" <cspitzer at cisco dot com>
- Date: Thu, 23 Aug 2001 17:13:13 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
first, you'll want to alphabetize the list based on city name so run this
stylesheet on the xml:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="people">
<people>
<xsl:apply-templates select="person"><xsl:sort
select="city"/></xsl:apply-templates>
</people>
</xsl:template>
<xsl:template match="person">
<person>
<city><xsl:value-of select="city"/></city>
<name><xsl:value-of select="name"/></name>
</person>
</xsl:template>
</xsl:stylesheet>
Then, do this:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="people">
<xsl:apply-templates select="person"/>
</xsl:template>
<xsl:template match="person">
<xsl:if test="not(preceding-sibling::person[1]/city=city)">
<xsl:text disable-output-escaping="yes">
</xsl:text> <!-- hard return to make it look pretty -->
<xsl:value-of select="city"/>
<xsl:text disable-output-escaping="yes">
</xsl:text> <!-- hard return to make it look pretty -->
</xsl:if>
<xsl:value-of select="name"/>
<xsl:text disable-output-escaping="yes">
</xsl:text> <!-- hard return to make it look pretty -->
</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Jeroen
Janssen
Sent: Thursday, August 23, 2001 4:24 PM
To: xsl-list@lists.mulberrytech.com
Subject: [xsl] grouping headers
Sorry for the subject line, I couldn't think of anything better :-) I'm
trying to do the following:
I have something like this xml:
<people>
<person>
<city>Amsterdam</city>
<name>John Doe</name>
</person>
<person>
<city>Amsterdam</city>
<name>Jane Doe</name>
</person>
<person>
<city>London</city>
<name>Jim Doe</name>
</person>
</people>
And would like this result in html:
Amsterdam
John Doe
Jane Doe
London
Jim Doe
I hope I'm making myself clear, I searched the archives for an answer but I
don't really know what I'm looking for...
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list