473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Simple XSLT questions.

Hello,

I am stumped and need some help.
I want to know how you can count the number of certain character
inside one element.

For example, counting commas.

<place>CA,USA</placeshould return 1

<place>Los Angeles,CA,USA</placeshould return 2

<place>90210,Los Angeles,CA,USA</placeshould return 3

May 9 '07 #1
7 2599
Use XSLT's string-manipulation functions. You may also have to write a
recursive template to iterate through the string.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
May 9 '07 #2
In article <11**********************@y5g2000hsa.googlegroups. com>,
anitawa <an*****@gmail.comwrote:
>I want to know how you can count the number of certain character
inside one element.

For example, counting commas.

<place>CA,USA</placeshould return 1

<place>Los Angeles,CA,USA</placeshould return 2

<place>90210,Los Angeles,CA,USA</placeshould return 3
Ok, here's a disgusting hack:

string-length(.)-string-length(translate(., ',', ''))

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
May 9 '07 #3
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote in
<f1**********@pc-news.cogsci.ed.ac.uk>:
In article
<11**********************@y5g2000hsa.googlegroups. com>,
anitawa <an*****@gmail.comwrote:
>>I want to know how you can count the number of certain
character inside one element.

Ok, here's a disgusting hack:

string-length(.)-string-length(translate(., ',', ''))
Looks elegant and not at all disgusting to me. Better than
coding a D&C named template to do something this trivial,
anyway.

--
Pavel Lepin
May 10 '07 #4
Pavel Lepin wrote:
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote in
>Ok, here's a disgusting hack:
string-length(.)-string-length(translate(., ',', ''))

Looks elegant and not at all disgusting to me. Better than
coding a D&C named template to do something this trivial,
anyway.
I agree; that's a good solution to the comma-counting problem.

(Cue the music: "Comma, comma, comma, Camellia; you come and go..."
Though I have to admit I spent years wondering what a "karma chameleon"
was.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
May 10 '07 #5
Joe Kesselman <ke************@comcast.netwrote in
<tp******************************@comcast.com>:
Pavel Lepin wrote:
>Richard Tobin <ri*****@cogsci.ed.ac.ukwrote in
>>Ok, here's a disgusting hack:
string-length(.)-string-length(translate(., ',', ''))

Looks elegant and not at all disgusting to me. Better
than coding a D&C named template to do something this
trivial, anyway.

I agree; that's a good solution to the comma-counting
problem.

(Cue the music: "Comma, comma, comma, Camellia; you come
and go..." Though I have to admit I spent years wondering
what a "karma chameleon" was.)
I always thought it was 'come a million', which usually made
me, well, a bit uneasy just thinking about it. But then, my
English listening comprehension ain't anything I'd
call 'good' even now, and it was even worse those days.

--
Pavel Lepin
May 10 '07 #6
Joe Kesselman wrote:
Pavel Lepin wrote:
>Richard Tobin <ri*****@cogsci.ed.ac.ukwrote in
>>Ok, here's a disgusting hack:
string-length(.)-string-length(translate(., ',', ''))

Looks elegant and not at all disgusting to me. Better than
coding a D&C named template to do something this trivial,
anyway.

I agree; that's a good solution to the comma-counting problem.

(Cue the music: "Comma, comma, comma, Camellia; you come and go..."
Though I have to admit I spent years wondering what a "karma chameleon"
was.)
I must be very warped. I got it first time I heard it.

///Peter
May 14 '07 #7

Peter Flynn <pe********@m.silmaril.iewrote in
<5a*************@mid.individual.net>:
Joe Kesselman wrote:
>Pavel Lepin wrote:
>>Richard Tobin <ri*****@cogsci.ed.ac.ukwrote in
Ok, here's a disgusting hack:
string-length(.)-string-length(translate(., ',', ''))

Looks elegant and not at all disgusting to me. Better
than coding a D&C named template to do something this
trivial, anyway.

I agree; that's a good solution to the comma-counting
problem.

I must be very warped. I got it first time I heard it.
By the way, just to let you know, the OP is quite grateful
for the solution. It's just that for some reason instead of
expressing his gratitude to you on the group, he expressed
his gratitude to you in my mail:

On Thursday 10 May 2007 22:15, you wrote:
[...]
Thats exactly what i was looking for.

Thanks a lot!
--
Pavel Lepin
May 14 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brett conklin | last post by:
I would like to not use the google groups as a crutch in my XSLT journey. What is the best xslt reference out there? Is it a book? Is it a web site? I am finding that I can come up with nearly...
9
by: Jeff Rubard | last post by:
I am curious to know whether anyone has experience using XSLT for web XML (non-XHTML) styling, either with CSS or standalone. I myself have engaged in rather unsuccessful experiments with the...
4
by: el_bandido | last post by:
Hello, I've tried the FAQ and some minutes in googl'ing but was not happy with what I got. Basically I'd like to get a _simple_ example on how I could create a web based (portable across all...
1
by: Mark | last post by:
I must say that I'm quite the newb with XML/XSLT. I kind of stubmled upon using it for a report I'm trying to make. If someone would be so kind as to help out with the following I would be...
2
by: sam | last post by:
Hi, I've been buried in xsl and xslt articles for several days now, and am still unsure as to what I need to do... Basically, my vb.net app loads up an XML file from an external source...
4
by: Gauthier | last post by:
Hi, I've a simple issue with the use of extension objects. I'm trying to call a text formating method from an object that I add to my arguments collection, this method take an input string and...
6
by: Christopher | last post by:
I am currently in the process of evaluating the performance hits of moving to the .NET platform for our application. I created a sample project that loads the transforms the same XML and XSLT in...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
2
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.