[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Occurences of comma-separated values

Subject: RE: Occurences of comma-separated values
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 30 Jul 2006 09:16:40 +0100
comma separated xslt
Your problem breaks into two halves: (a) tokenizing, and (b) grouping.

Both steps are much easier with XSLT 2.0 than 1.0. In 2.0 it's simply

<xsl:for-each-group select="list/*/@ids/tokenize(.,',')" group-by="."/>
  <xsl:sort select="current-grouping-key()"/>
  <xsl:value-of select="current-grouping-key()"/>
  <xsl:text>: </xsl:text>
  <xsl:value-of select="count(current-group())"/>

For XSLT 1.0 you can learn about tokenizing by looking at the string
functions/templates at www.exslt.org, and you can learn about grouping at

Michael Kay

> -----Original Message-----
> From: Smoother@xxxxxx [mailto:Smoother@xxxxxx]
> Sent: 29 July 2006 15:08
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Occurences of comma-separated values
> For instance, I have the following XML-File:
> <list>
>   <item1 ids="a,b,c,e" />
>   <item2 ids="b,c,d" />
>   <item3 ids="a,c,d,e" />
>   <item4 ids="e,f" />
>   <item5 ids="a,c,d,e,g" />
> </list>
> I contemplate how to count the occurences of
> (a) all ids (e.g. 'a') in the document and
> (b) to count the occurences of a specific (known) id (e.g.
> 'f') in the document.
> For case a the output should be like this:
> a: 3
> b: 2
> c: 4
> d: 3
> e: 4
> f: 1
> g: 1
> I started to learn XSL yesterday. For several other problems,
> I found an easily adaptable solution on the web, numerous
> time on this list here.
> But for my current problem, there was no such help available.
> Of course, I found here a similar posting which deals with
> occurences of equal nodes
> (http://www.stylusstudio.com/xsllist/200309/post20830.html),
> but I don't know how to adapt it. So please find a solution
> and help me and others who have the same problem.
> Thanks in advance,
> S. Renault
> --
> Echte DSL-Flatrate dauerhaft f|r 0,- Euro*. Nur noch kurze Zeit!
> "Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.