I always seem to have trouble with xpath axis expressions...
In some expressions I have used ../
to refer to the parent node, but is that not valid for test
expressions? Or is my syntax just wrong?
<xsl:when test="../../[@status='current']">
My goal is to apply an attribute inside the xsl:when
IF the parent's parent has a status attribute with a value of 'current'.
EDIT: self::parent/parent[@status='current']
is a valid xpath expression and may be what I want, can anyone confirm? I might not be going far enough.
Hey Hemant, we can use the double dot (“..”) to access the parent of any node using the XPath. For example – The locator //span[@id=”first”]/.. will return the parent of the span element matching id value as 'first.
IN the XPath we can traverse backward using the double dots(..). We can traverse backward as many levels as we want like ../../… For example, if we want to find the parent of any child div selector then we can use it as.
Current node is the node that the XPath processor is looking at when it begins evaluation of a query. In other words, the current node is the first context node that the XPath processor uses when it starts to execute the query. During evaluation of a query, the current node does not change.
The difference between parent:: and ancestor:: axis is conveyed by their names: A parent is the immediately direct ancestor. So, yes /a/b/c/d/ancestor::*[1] would be the same as /a/b/c/d/parent::* .
The problem is in /[
. You can change it to
../../self::*[@status='current']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With