I have seen questions where following-sibling has been applied based on a node's value but my issue is related to the actual node itself.
This is the type of XML I have have:
<Employee>
<Summary>
<A>
<B>
</Summary>
<Elections>
</Elections>
<Employee>
I need to write a Xpath condition as follows:
if (NOT(the following sibling(first sibling) of /Employee/Summary is Elections)), then do something.
Currently I have:
<xsl:if test="(not(following-sibling::Employee/Summary[1]='Earnings'))
<xsl:call-template name="EmployeeRecord"/>
</xsl:if>
Please note that I am not checking a node value but the node itself(i.e the node name). Any help in the right direction will be much appreciated.
We can use the concept of following-sibling in xpath for identifying elements in Selenium. It identifies the siblings of the context node. The siblings should be located at the equal level of the existing node and should have the same parent.
The following-sibling axis indicates all the nodes that have the same parent as the context node and appear after the context node in the source document.
The only difference in functionality is that of preceding. So, here, in contrast to Following-Sibling, you get all the nodes that are siblings or at the same level but are before your current node. The syntax for using Preceding-Sibling is: //tagname[@attribute='value']//preceding-sibling::tagname.
You are on the right track. The following-sibling
axis evaluates from the context node in the previous step.
if you are looking for the first element that is the following-sibling of /Employee/Summary
, you would use: /Employee/Summary/following-sibling::*[1]
.
In order to evaluate whether that first following-sibling is an Elections
element, you can use an additional predicate filter [self::Elections]
.
not()
Putting it all together, adjusting your example:
<xsl:if test="not(/Employee/Summary/following-sibling::*[1][self::Elections])">
<xsl:call-template name="EmployeeRecord"/>
</xsl:if>
I need to write a Xpath condition as follows:
if (NOT(the following sibling(first sibling) of /Employee/Summary is Elections)), then do something.
Use:
not(/Employee/Summary/following-sibling::*[1][self::Elections])
The XPath expression that is specified as argument to the not()
function selects any Elections
element that is the first following-sibling element of any Summary
element that is a child of the top element Employee
.
If this doesn't select any node, then the XPath expression above evaluates to true()
.
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