RE: [xsl] grouping headers
by Corey Spitzer other posts by this author
Aug 23 2001 10:13PM messages near this date
Re: [xsl] grouping headers
|
Re: [xsl] grouping headers
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@[...].com
[mailto:owner-xsl-list@[...].com]On Behalf Of Jeroen
Janssen
Sent: Thursday, August 23, 2001 4:24 PM
To: xsl-list@[...].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
Thread:
Elisabeth Kaminski
Jeroen Janssen
Jeni Tennison
Corey Spitzer
Jeni Tennison
Robert Koberg
Elisabeth Kaminski
Robert Koberg
Elisabeth Kaminski
Robert Koberg
Robert Koberg
Elisabeth Kaminski
|