RE: Getting a node's cousin

Subject: RE: Getting a node's cousin
From: "Harbarth, Juliane" <jhb@xxxxxxxxxxxxxx>
Date: Wed, 11 Aug 1999 17:07:10 +0200
>
> Given this XML
> <data>
> <parent>parent1
> <child>child1
> <grandchild>child1_of_child1</grandchild>
> <grandchild>child2_of_child1</grandchild>
> </child>
> <child>child2
> <grandchild>child1_of_child2</grandchild>
> <grandchild>child2_of_child2</grandchild>
> </child>
> </parent>
>
> when I am processing a grandchild, how can I access the immediate next set
of
> grandchildren, ie my sibling's children (hence my cousin term)  
>

    	<xsl:template match="grandchild">
	 <P>Current Node    : <xsl:value-of select="."/>
	  <BR />
	  Next Grandchild : 
	  <xsl:choose>
	   <xsl:when test="position()=last()">
	    <xsl:value-of
select="parent::child/following-sibling::child[1]/child::grandchild[1]"/>
	   </xsl:when>
	   <xsl:otherwise>
	    <xsl:value-of select="following-sibling::grandchild[1]"/>
	   </xsl:otherwise>
	  </xsl:choose>
         </P>
    	</xsl:template>

The seventh line says : select the 'child' element of the parent axis 
('child' denoting the element's QName), from there select the first
follwing sibling, and from there select the first child ('child' herein
denoting the children's axis). 

Juliane.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread