xsl-list
[Top] [All Lists]

Counting uniquely selected values of elements

2003-04-14 05:45:16
Hi all,

I have tried to make a subject title as descriptive as possible, but I don't know if I have succeded very well.

Anyway, here is my problem:

I have a source.xml that has the following structure:

<root>
 <a><b><c>this</c></b></a>
 <a><b><c>that</c></b></a>
 <a><b><c>that</c></b></a>
 <a><b><c>not this</c></b></a>
 <a><b><c>not that</c></b></a>
 <a><b><c>this</c></b></a>
 <a><b><c>this</c></b></a>
</root>

I want to count the occurences of each text in the c element (this, that, not this, not that).

I have tried something like:

<xsl:template match="/">
 <xsl:apply-templates select="root"/>
</xsl:template>

<xsl:template match="root">
 <xsl:apply-templates select="a/b/c[not(preceeding::a/b/c)]"/>
<!-- This is not right, but I don't have any clue what to put into the select statement -->
</xsl:template>

<xsl:template match="a/b/c">
 <xsl:value-of select="."/> occurs
 <xsl:value-of select="count(preceeding::a/b/c=.)"/> times.
 <!-- Syntax is not right here either -->
</xsl:template>

It is especialy the nested a/b/c (instead of just c) that throws me off, but I have never tried counting either.

Thanks in advance!

Ragulf Pickaxe :)

_________________________________________________________________



XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>