473,471 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 15669
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Martin Nadoll | last post by:
Hello, I am working on a form-validation script. There is a input-field where you input a float or integer numper (maximum price to output in database-query). But my Cold-Fusion Query...
10
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could...
3
by: Dana King | last post by:
I'm looking for some other developers opinions, I'm trying to find the best way to count strings within a string using VB.net. I have tested five methods and have found the String.Replace method...
5
by: fressanme | last post by:
im trying to create this crossout puzzle generator..ill try to upload my code later since i dont have it at the moment..but the problem im trying to look into is how to count the number of characters...
6
by: bgeyer14 | last post by:
Hello I am writing a program that I have gotten stuck on. I have gotten the characters to show but don't know how to do and get the vowels and consonants ...
12
by: KWSW | last post by:
Got this assignment due a few weeks later and since I am done with the up coming assignment, decided to try out the next one early rather than rush later. First part of it requires me to do a...
5
by: Dean | last post by:
Hi, I have a table with non-unique identifiers. I need to take all the values with the same ID's and combine them into one field with a semicolon as a seperator. These values may exceed 255...
3
by: waynejr25 | last post by:
can anyone debug my program and get it to run. #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <map> using namespace std;
3
by: cppman | last post by:
Hello, I am very new to C++ programming. I am trying to read a file with very large strings back to back, no commas or any other seperations between characters in a string and the size of the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.