Simple XSLT questions.

A

anitawa

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</place> should return 1

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

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

Joseph Kesselman

Use XSLT's string-manipulation functions. You may also have to write a
recursive template to iterate through the string.
 
R

Richard Tobin

anitawa said:
I want to know how you can count the number of certain character
inside one element.

For example, counting commas.

<place>CA,USA</place> should return 1

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

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

Ok, here's a disgusting hack:

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

-- Richard
 
P

Pavel Lepin

Richard Tobin said:
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.
 
J

Joe Kesselman

Pavel said:
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.)
 
P

Pavel Lepin

Joe Kesselman said:
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.
 
P

Peter Flynn

Joe said:
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
 
P

Pavel Lepin

Peter Flynn said:
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:

]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,008
Messages
2,570,268
Members
46,868
Latest member
OrvalRitch

Latest Threads

Top