Thread: Ordering lists
View Single Post
Old June 6th, 2003, 03:30 PM
POL POL is offline
Registered User
Join Date: Jun 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ordering lists

I have a list of several dozens cities in XML format organized in no particular order such as this:

<cityName>San Francisco</cityName>

<stateName>North Carolina</stateName>


By using XSLT I want to organize in alphabetic order by states and by cities within each state, the state name should appear only once on top of cities located within every particular state.

State name a
  City name A
  City name B
  City name C

State name b
  City name A
  City name B
  City name C
  City name D

I tried this:

<xsl:apply-templates select="cities/city">
<xsl:sort select="stateName" />
<xsl:sort select="cityName" />

<xsl:template match="city">

<xsl:if test="preceding-sibling::*[1]/stateName != stateName" >
<xsl:value-of select="stateName" />
<xsl:value-of select="cityName" />

The problem is that once I execute this all cities are preceded by a stateName.

Thanks for helping me.