I tried adding /text() to an expression that also returns nothing
This selects all text node node context detectors β and there are three of them.
What you call "nothing" is most likely the first of them, which is the text of only the white space node (so you see "nothing" in it).
What do you need :
//span[@id='span-id']/text()[3]
Of course, other options are possible :
//span[@id='span-id']/text()[last()]
Or:
//span[@id='span-id']/br/following-sibling::text()[1]
XSLT Based Validation :
<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="node()|@*"> "<xsl:copy-of select="//span[@id='span-id']/text()[3]"/>" </xsl:template> </xsl:stylesheet>
This conversion simply displays all the expressions selected by XPath. When applied to the provided XML document (comment deleted):
<span id="span-id"> <b>bold title</b> <br/> text here that I want to grab.... </span>
The desired result is obtained :
" text here that I want to grab.... "
Dimitre novatchev
source share