xml - XSLT - Add incrementing id attribute to the nodes -
i have xml this,
<doc> <section>1<section> <section>1<section> <p>22</p> <p>22</p> <p>22</p> <footer></footer> <footer></footer> <footer></footer> </doc> what need id add new attribute <footer> nodes. output be
<doc> <section>1<section> <section>1<section> <p>22</p> <p>22</p> <p>22</p> <footer id="number-1"></footer> <footer id="number-2"></footer> <footer id="number-3"></footer> </doc> i can add new attribute <footer> node problem i'm facing add incrementing ids in xslt.
<xsl:template match="footer"> <xsl:copy> <xsl:attribute name="id"><xsl:value-of select="'number-'[position()]"/></xsl:attribute> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> i've tried use xsl variable since it's cannot change other languages couldn't it. tried position() function gives position of current node.so case id numbers stating 6.
can suggest me solution. in advance
you use
<xsl:attribute name="id"> <xsl:value-of select="'number-'"/> <xsl:number level="any"/> </xsl:attribute>
Comments
Post a Comment