tags:

views:

222

answers:

1

Hi,

I am new to XPath. I am writing a code to grab all the 3 digit numbers from a page. They are not constant, varying between 105, 515, and 320. I want two be able to tokenize these numbers into two separate pieces...

i would love to be able to grab the first digit in one X-path expression and the second two digits in a second X-Path expression

on doing my research I came across that you couldn't tokenize with 'zero value,' but is there any way to do this?

Thanks

+1  A: 

It seems to me that the question is actually about the possible ways to split a 3-digit number into two strings, the first containing the first digit and the second containing the remaining two digits.

Here is one possible solution:

The following XPath expression when evaluated produces a string containing the first digit of a number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

  substring($vNum, 1, 1)

The following XPath expression when evaluated produces a string containing the last two digits of a 3-digit number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

  substring($vNum, 2)

In case if we are not sure about the number of digits $vNum has, the following XPath expression when evaluated produces a string containing the two digits that immediately follow the first digit of a 3+ digit number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

  substring($vNum, 2, 2)

And lastly, if we again don't know the exact number of digits, but want to get the last two of them, the following XPath expression when evaluated produces a string containing the two digits at the end of a 2+ digit number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

 substring($vNum, string-length($vNum) - 1)
Dimitre Novatchev
Very nice summary answer!
geoffc