Reputation: 11
How do I get a specific numeric value?
how can I get only the digit "6" ?
example "ตอนที่ 6" i need only output for "6" or " 6 "
i'm try //li[@class='active']/text()
for simple get text, but i not sure how should i do next
Upvotes: 0
Views: 229
Reputation: 243449
The way to do this, without even knowing what non-digit characters could be there, is using the double-translate method:
translate(//li[@class='active']/text(),
translate(//li[@class='active']/text(), '0123456789', ''),
'')
Explanation:
The inner translate(//li[@class='active']/text(), '0123456789', '')
gets all non-digit characters in the first argument.
The outer translate()
replaces all those non-digit characters, found in the inner translate()
with the empty string.
What remains are only the digit characters
XSLT - based verification:
Given this simplified XML document:
<t>ตอนที่ 6</t>
The following transformation evaluates the correct (solution) XPath expression and outputs the result of this evaluation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/*">
<xsl:value-of select="translate(., translate(., '0123456789', ''), '')"/>
</xsl:template>
</xsl:stylesheet>
The wanted result is produced:
6
Upvotes: 0
Reputation: 29022
You can try this XPath-1.0 expression:
normalize-space(substring-before(substring-after(//li[@class='active']/text(),'ตอนที่ '),'"'))
You can also use XPath-2.0's fn:replace
function to use a RegEx to filter the string:
normalize-space(replace(//li[@class='active']/text(),'.*
\s*".*(\d+)\s*".*','$1'))
This RegEx may have to be adjusted. It consists of several parts:
.*

matches the whole "::before" line\s*".*
matches the string " ตอนที่
(\d+)
selects one or more numbers later copied to the output with $1
\s*".*
matches the rest of the line " = 50
Upvotes: 1