/ / XSLT - ノードに増分ID属性を追加 - xml、xslt、xslt-2.0

XSLT - ノードにインクリメントID属性を追加する - xml、xslt、xslt-2.0

私はこのような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> nodeしかし私が直面している問題はXSLTにインクリメントIDを追加することです。

<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() ただし、現在のノードの位置のみが表示されます。この場合、6から始まるID番号です。

あなたは私に解決策を提案できますか。前もって感謝します

回答:

回答№1は2

あなたは使うことができます

<xsl:attribute name="id">
<xsl:value-of select=""number-""/>
<xsl:number level="any"/>
</xsl:attribute>