简体   繁体   中英

Get number via XPath?

There's a part of the page:

<p>
  349
  <span>
    $
  </span>
</p>

How to get "349"?

There are many XPaths that will select "349" from that XML. Here are a few:

  • Select the space-normalized text node children of p :

     normalize-space(/p/text())
  • Select the space-normalized substring before the $ in the string value of p :

     normalize-space(substring-before(/p, '$'))
  • Select space-normalized, numeric text nodes anywhere in the document:

     normalize-space(//text()[number(.) = .])

All of these XPaths will select "349" as a string as requested. You could also wrap any of the above expressions with a number() function call if you actually want 349 as a number rather than as a string.

由于您没有显示完整的页面,我们没有完整的路径,但试试这个:

 /p/text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM