Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for the immediate following sibling of parents in xpath

Tags:

xpath

I am now using xpath to test a node's parent node's immediate following sibling(uncle or ant) node.

My xml looks like

<MyParent>
 <A>
 <B>
 <C>
</MyParent>

<Uncle>
 ..
</Uncle>

Now I am in the template match for child node B, and I want to test if the immeididate following-sibling of my parent is called "Uncle",

I tried the following two xpaths:

<xsl:if test="parent::MyParent/following-sibling::*[1][self::Uncle]">
     <xsl:text>we have it</xsl:text>        
</xsl:if>

and

<xsl:if test="parent::MyParent[following-sibling::*[1][self::Uncle]]">
     <xsl:text>we have it</xsl:text>        
</xsl:if>

neither of them will work, could experts help debug where I made mistakes? Thanks :).

like image 413
Kevin Avatar asked Sep 29 '11 17:09

Kevin


1 Answers

Try this.

../following-sibling::*[position()=1][name()='Uncle'] 
like image 88
MNGwinn Avatar answered Nov 15 '22 22:11

MNGwinn