Custom Search
Logiclabz
  • Home
  • XML/XSLT
  • Get Previous Node / preceding-sibling in XSLT (XPath)

Get Previous Node / preceding-sibling in XSLT (XPath)

"preceding-sibling::<<Node Name>>" can be use to get all the previous siblings. But to get the just before sibiling syntax is like below "preceding-sibling::<<Node Name>>[<<count>>]"

Sample XML doc

<Parents>
       <Child id="1" name="Yogesh1" mode="1" />
       <Child id="2" name="Yogesh2" mode="1" />
       <Child id="3" name="Yogesh3" mode="2" />
       <Child id="4" name="Yogesh4" mode="2" />
       <Child id="5" name="Yogesh5" mode="2" />
</Parents>
Sample XSLT Template for preceding-sibling
<xsl:template match="Child">
       <xsl:if test="@mode != preceding-sibling::Child[1]/@mode">
              <xsl:value-of select="Change in mode Attribute" />
       </xsl:if>
       Name:<xsl:value-of select="@name" />
       Id:<xsl:value-of select="@id" />
</xsl:template>



Leave a reply


Do you like this post?