Xml 在XSLT1.0中生成序列号
我想使用XSLT1.0在xml的输出中获得一个序列号Xml 在XSLT1.0中生成序列号,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我想使用XSLT1.0在xml的输出中获得一个序列号 `<a> <b> <c> <d>text1</d> </c> <c> <d>text2</d> </c> </b> <b> <c> <d>text3</
`<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>`
`
文本1
文本2
文本3
文本4
`
输出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> `.
`
1.
文本1
2.
文本2
3.
文本3
4.
文本4
`.
请提供任何建议。使用
xsl:number level=“Any”
:
可以使用position()
<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>
<xsl:template match="/">
<result>
<xsl:apply-templates select="//d"/>
</result>
</xsl:template>
<xsl:template match="d">
<seq>
<xsl:value-of select="position()"/>
</seq>
<r>
<xsl:value-of select="."/>
</r>
</xsl:template>