在 xslt 1.0 中生成序列号 [英] Generate a sequence number in xslt 1.0
本文介绍了在 xslt 1.0 中生成序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在使用 xslt 1.0 的 xml 输出中获取序列号.
I want to get a sequence number in the output of the xml using xslt 1.0.
`<a>
<b>
<c>
<d>text1</d>
</c>
<c>
<d>text2</d>
</c>
</b>
<b>
<c>
<d>text3</d>
</c>
<c>
<d>text4</d>
</c>
</b>
</a>`
输出的xml应该像
` <result>
<seq>1</seq>
<r>text1</r>
<seq>2</seq>
<r>text2</r>
<seq>3</seq>
<r>text3</r>
<seq>4</seq>
<r>text4</r>
</result> `.
请提出任何建议.
推荐答案
使用 xsl:number level="any"
:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="a">
<result>
<xsl:apply-templates select=".//d"/>
</result>
</xsl:template>
<xsl:template match="d">
<seq><xsl:number level="any"/></seq>
<r><xsl:value-of select="."/></r>
</xsl:template>
</xsl:stylesheet>
这篇关于在 xslt 1.0 中生成序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文