XSLT find whether sibling exist or not
xpath, xslt
Solution
If you want to test if an element has a sibling following it, you can use the sensibly named "following-sibling" xpath expression:
<xsl:if test="following-sibling::*" />
Note that this will test if there is any following-sibling. If you only wanted to test for mapNode elements, you could do this
<xsl:if test="following-sibling::mapNode" />
However, this would also be true also in the following case, because following-sibling will look at all following siblings:
<mapNode>
<mapNode>...</mapNode>
<mapNode>...</mapNode>-----I am here at 2
<differentNode>...</differentNode>
<mapNode>...</mapNode>
</mapNode>
If you therefore want to check the most immediately following sibling was a mapNode element, you would do this:
<xsl:if test="following-sibling::*[1][self::mapNode]" />
Problem
Sample XML is given below. ``` <mapNode> <mapNode>...</mapNode> <mapNode>...</mapNode>-----I am here at 2 <mapNode>...</mapNode> <mapNode>...</mapNode> </mapNode> <mapNode> <mapNode>...</mapNode> <mapNode>...</mapNode> </mapNode> ``` I want to know whether position 3 exist or not. Please help me. Thanks in advance.