我有这样的xml,
<doc>
<section>1<section>
<section>1<section>
<p>22</p>
<p>22</p>
<p>22</p>
<footer></footer>
<footer></footer>
<footer></footer>
</doc>我需要做的是,id向<footer>节点添加新属性。所以输出将是
<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>我可以向<footer>节点添加新属性,但我面临的问题是在XSLT中添加递增is。
<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>我尝试过使用xsl变量,但是由于它不能像其他语言那样改变,所以我无法这样做。另外,我尝试使用position()函数,但它只给出了当前node.so的位置,这是从6开始的id号。
你能给我一个解决办法吗。提前感谢
发布于 2015-07-09 01:22:28
你可以用
<xsl:attribute name="id">
<xsl:value-of select="'number-'"/>
<xsl:number level="any"/>
</xsl:attribute>https://stackoverflow.com/questions/31289652
复制相似问题