XSLT Selecting characters in string

R

requeth

Allo,

I'm a little confused. I have an XSLT, in which my parser selects a
node, but I want to just capture the first two characters to a
variable. How would I do this? I know how to create the variable, but
I'm not sure how to take just the first two characters of the string.

Thanks,

RT Starid
 
J

Joseph Kesselman

variable. How would I do this? I know how to create the variable, but
I'm not sure how to take just the first two characters of the string.

XSLT and XPath come with a function library that includes the
traditional substring function. Just set the variable to an XPath
expression that invokes it. For example, if you want the truncated value
of the current node's foo attribute, you could write

<xsl:variable name="myvar" select="substring(@foo,0,2)


http://www.w3.org/TR/1999/REC-xpath-19991116#section-String-Functions
(though it looks like there's a typo in one of the examples).
 
D

Dimitre Novatchev

<xsl:variable name="myvar" select="substring(@foo,0,2)


XPath is 1-based. Therefore, the expression to produce the substring,
consisting of the first two characters in the string value of @foo is:

substring(@foo, 1, 2)


Cheers,
Dimitre Novatchev
 
J

Joe Kesselman

Dimitre said:
XPath is 1-based. Therefore, the expression to produce the substring,
consisting of the first two characters in the string value of @foo is:
substring(@foo, 1, 2)

Whups. Yes, my bad. I'm coding in three languages at once these days,
and I got confused.
 

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,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top