xsl-list
[Top] [All Lists]

RE: This could be simple, but not for me!

2004-05-25 06:46:20

Thanks, Andrew

This is very very close to what I need. But the city name has 
to be there only once for all names like:


100, Red
    City1
        Name1
        Name10
        Name100
        ...etc

    City2
        Name4
        Name40
        ...

200, Blue
    City1
        Name2
        Name20
        ...

    City2
        Name5
        ...

300, Green
    City1
        Name3
        Name30
        Name300
        Name3000
        ...

400, Yellow
    City2
        Name6
        ...

Is that possible as well?


Sure, just add an extra key and an if test around the value-of to check
if it's the first occurance of that value:

<xsl:key name="cities" match="City" use="."/>

and the if test:

<xsl:if test="generate-id(ancestor::Community/City) =
generate-id(key('cities',ancestor::Community/City)[1])">
  <span><xsl:value-of select="ancestor::Community/City"/></span>
</xsl:if>

Now, this might fail at the moment because I'm guessing at the structure
of your xml, if its anything other that one <City> per <Community> then
you will need to adjust it.

cheers
andrew