XPath to return string concatenation of qualifying child node values
In XPath 2.0 : string-join(/*/node()[not(self::p)], ”)
In XPath 2.0 : string-join(/*/node()[not(self::p)], ”)
In XPath 1.0 one way to do this is by using the Kayessian method for node-set intersection: $ns1[count(.|$ns2) = count($ns2)] The above expression selects exactly the nodes that are part both of the node-set $ns1 and the node-set $ns2. To apply this to the specific question — let’s say we need to select all nodes … Read more
Test the value against NaN: <xsl:if test=”string(number(myNode)) != ‘NaN'”> <!– myNode is a number –> </xsl:if> This is a shorter version (thanks @Alejandro): <xsl:if test=”number(myNode) = myNode”> <!– myNode is a number –> </xsl:if>
Use name(). (Find docs for newer versions of the XPath language here.) Here are modified versions of your example: Works in XPath 2.0+ only: //element/*[@id=’elid’]/name() Works in XPath 1.0 and 2.0+*: name(//element/*[@id=’elid’]) *If using 2.0+, the expression //element/*[@id=’elid’] must only return one element. Otherwise you’ll get an error like A sequence of more than one … Read more
Absolute Xpath: It uses Complete path from the Root Element to the desire element. Relative Xpath: You can simply start by referencing the element you want and go from there. Relative Xpaths are always preferred as they are not the complete paths from the root element. (//html//body). Because in future, if any webelement is added/removed, … Read more
With the path /foo/bar/comment() you can select all comments in the /foo/bar element. May depend on your language of choice, of course. But generally this is how you do it.
/Obj/Name/text() is the XPath to return the content of the CDATA markup. What threw me off was the behavior of the Value property. For an XMLNode (DOM world), the XmlNode.Value property of an Element (with CDATA or otherwise) returns Null. The InnerText property would give you the CDATA/Text content. If you use Xml.Linq, XElement.Value returns … Read more
You could do it this way: ../node[not(text()) and preceding-sibling::node[@id][1][@id=’1′]] where ‘1’ is the id of the current node (generate the expression dynamically). The expression says: from the current context go to the parent select those child nodes that have no text and from all “preceding sibling nodes that have an id” the first one must … Read more
The ends-with function is part of xpath 2.0 but browsers (you indicate you’re testing with chrome) generally only support 1.0. So you’ll have to implement it yourself with a combination of string-length, substring and equals substring(@id, string-length(@id) – string-length(‘register’) +1) = ‘register’
All title nodes with zipcode or book node as parent: Version 1: //title[parent::zipcode|parent::book] Version 2: //bookstore/book/title|//bookstore/city/zipcode/title Version 3: (results are sorted based on source data rather than the order of book then zipcode) //title[../../../*[book] or ../../../../*[city/zipcode]] or – used within true/false – a Boolean operator in xpath | – a Union operator in xpath that … Read more