469,336 Members | 5,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

XSL count specific characters in string

Hi -

Using XSL I need to count the number of times character appears in a
string. My guess is I need to recurse through the value of x, but I'm
having trouble getting my head around the solution. In the example
below I'd like to count the number of '-' in x and write the sum to y.
<x>10-10-10</x>
<x>10-10-100</x>
<x>10-100-10</x>
<x>10-10</x>
<x>10-10-10-100</x>

<y>2</y>
<y>2</y>
<y>2</y>
<y>1</y>
<y>3</y>
Can anyone point me in the right direction?

Thanks,

Jerry

Jul 20 '05 #1
2 15370
Tempore 03:42:58, die Thursday 13 January 2005 AD, hinc in foro {comp.text.xml} scripsit Jerry <jo******@jerryo.com>:

Using XSL I need to count the number of times character appears in a
string. My guess is I need to recurse through the value of x, but I'm
having trouble getting my head around the solution. In the example
below I'd like to count the number of '-' in x and write the sum to y.


If the string to search for contains only one character, like in your example, you might use this:

<xsl:template match="x">
<y><xsl:value-of select="string-length(.)-string-length(translate(.,'-',''))"/></y>
</xsl:template>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
Jul 20 '05 #2
Joris -

This is perfect and very clever.

Much thanks,

Jerry Orabona

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Martin Nadoll | last post: by
10 posts views Thread by Jon | last post: by
6 posts views Thread by bgeyer14 | last post: by
12 posts views Thread by KWSW | last post: by
3 posts views Thread by waynejr25 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.