Subject:Apply-templates and processing nodes Author:KJ KJ Date:27 Aug 2008 02:08 AM Originally Posted: 27 Aug 2008 02:06 AM
Hello,
I have a xml with below structure
<r1>
<c1 value="1">
<gc1 value="1"> <!-- need to check this node value and process other siblings-->
<gc2 value="2">
<gc3 value="3">
<gc4 value="4">
<gc5 value="5">
</c1>
<!-- all below nodes are just need to be copied into target xml doc -->
<c2 value="2">
<gc1 value="1">
<gc2 value="2">
<gc3 value="3">
<gc4 value="4">
<gc5 value="5">
</c2>
.
.
.
.
.<!-- Some more nodes are here-->
.
.
.
</r1>
I have a xslt to process node /r1/c1/gc1 as below, which works fine except:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" .......>
.
.
.
.
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match ="r1">
<root>
<xsl:apply-templates select="node()" />
<xsl:apply-templates select ="c1/gc1" />
</root>
</xsl:template>
<xsl:template match="c1/gc1>
<!-- check the value attribute (1) for this node and process it -->
</xsl:template>
.
.
.
.</xsl:stylesheet>
This xslt calls [template match="c1/gc1"] twice bcs of <xsl:template match="node()"> in the top.
Ideally, i need to process the nodes in r1/c1 and copy up all other elements as it is.
could any one post, how to rewrite this xslt?
ps. I understand that by removing
<xsl:apply-templates select ="c1/gc1" /> line will work perfectly, though is there a way to give a name for this node and exclude it from processing again?