How to get a part of a string in XSL?

D

Diandian Zhang

Hi, everyone,

I have a problem in getting a substring.
In the following XML code, I just want to get the 7 of the "7dt0".
With "<xsl:variable name="var1" select="A_range/text()"/>", I can get
"

7dt0 ".
How can I continue with the var1 to get 7 from it?

Thanks a lot!

<A_range>
<Size>8</Size>
<Decimal>255</Decimal>
<Hex>0xff</Hex>

7dt0 </A_range>
 
M

Martin Honnen

Diandian said:
I have a problem in getting a substring.
In the following XML code, I just want to get the 7 of the "7dt0".
With "<xsl:variable name="var1" select="A_range/text()"/>", I can get
"

7dt0 ".
How can I continue with the var1 to get 7 from it?
<A_range>
<Size>8</Size>
<Decimal>255</Decimal>
<Hex>0xff</Hex>

7dt0 </A_range>

You could use
substring(normalize-space(/A_range/text()[last()]), 1, 1)
see the definition of string functions in the XPath 1.0 specification:
<http://www.w3.org/TR/xpath#section-String-Functions>
XSLT 1.0 uses XPath 1.0 so all the functions defined in XPath 1.0 are
available in XSLT 1.0.
 

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
473,999
Messages
2,570,246
Members
46,840
Latest member
BrendanG78

Latest Threads

Top