[xsl] Counting uniquely selected values of elements

Subject: [xsl] Counting uniquely selected values of elements
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Mon, 14 Apr 2003 12:45:16 +0000
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


Current Thread