xpath
How do I use XPath with a default namespace with no prefix?
The configuration element is in the unnamed namespace, and the MyNode is bound to the lcmp namespace without a namespace prefix. This XPATH statement will allow you to address the MyNode element without having declared the lcmp namespace or use a namespace prefix in your XPATH: /configuration/*[namespace-uri()=’lcmp’ and local-name()=’MyNode’] It matches any element that is … Read more
Xpath expression to find values that start with
I think this xpath should work //id[starts-with(text(),’Annotations’)]
XPath operator “!=”. How does it work?
Recommendation: Never use the != operator to compare inequality where one or both arguments are node-sets. By definition the expression: $node-set != $value evaluates to true() exactly when there is at least one node in $node-set such that its string value is not equal to the string value of $value. Using this definition: $empty-nodeset != … Read more
How to get the preceding element?
You can use this xpath: //a[.=”Next.”]/preceding::a[1] If I were to diagram it out, using an X to represent the current location, it would look like this: ——————+——+—————— preceding-sibling | self | following-sibling ——————|——|—————— last() … 2 1 | X | 1 2 … last() ——————+——+——————
XPath – select text after certain node
Try this: //foo/following-sibling::text()[1] (replace //foo/ with your current XPath expression. With this XML: <data> <foo>foo</foo> bar <baz>baz</baz> </data> it gives bar as output.
How to add multiple test conditions in ‘test’ attribute expression of tag
<xsl:if test=”$var=”ab” | $var=”bc” | $var=”ca” “> This is wrong — you are using the XPath union operator | on boolean values. Solution: use the XPath or operator: <xsl:if test=”$var=”ab” or $var=”bc” or $var=”ca” “> The above XPath expression (the value of the test attribute) can be optimized, so that only one comparison is made … Read more
Excel – Extract substring(s) from string using FILTERXML
Excel’s FILTERXML uses XPATH 1.0 which unfortunately means it is not as diverse as we would maybe want it to be. Also, Excel seems to not allow returning reworked node values and exclusively allows you to select nodes in order of appearance. However there is a fair share of functions we can still utilize. More … Read more
count of element in XPath
You can try the following: count(//element/Element1[namespace-uri()=’mynamespace’])
XPath //div[contains(text(), ‘string’)] fails to select divs containing ‘string’
Replace text() with string(): //div[contains(string(), “Elangovan”)] Or, you can check that span‘s following text sibling contains the text: //div[contains(span/following-sibling::text(), “Elangovan”)] Also see: Difference between text() and string()