I have xml like follows,
<doc>
<session>
<a type="abc">
<b>contetnt</b>
<c>contetnt</c>
</a>
<a type="abc">
<b>contetnt</b>
<c>contetnt</c>
</a>
<a type="abc">
<b>contetnt</b>
<c>contetnt</c>
</a>
<d></d>
<e></e>
<f></f>
</session>
</doc>
my requirements are,
1) add node just before the end of node
2) nodes which are in current document should place under the newly created node
3) add dynamically increment id to node
so the output should be
<doc>
<session>
<d></d>
<e></e>
<f></f>
<end>
<a idNo="1" type="abc">
<b>contetnt</b>
<c>contetnt</c>
</a>
<a idNo="2" type="abc">
<b>contetnt</b>
<c>contetnt</c>
</a>
<a idNo="3" type="abc">
<b>contetnt</b>
<c>contetnt</c>
</a>
</end>
</session>
</doc>
I wrote following xsl to do this task,
<!-- copy all element -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- add dynamic id -->
<xsl:template match="a">
<xsl:copy>
<xsl:attribute name="idNo">
<xsl:number count="a"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- create <end> node and copy <a> nodes -->
<xsl:template match="session">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<end>endNode</end>
<xsl:copy-of select="a"/>
</xsl:copy>
</xsl:template>
<!-- remove original <a> nodes-->
<xsl:template match="a"/>
when I run these xsl separately they run fine but when I run them all I get an ambiguous template matching error.
My xsl codes are correct but I'm having a problem of organize them in right order to achieve my task.
can anyone suggest an method to organize these code in correct manner to achieve my task?