您应该首先从XSLT标识模板开始,将所有元素复制到未更改的。。。
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
li
<xsl:template match="li">
<xsl:element name="li{count(ancestor::li) + 1}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
注意,花括号表示
Attribute Value Template
试试这个XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="no" />
<xsl:template match="li">
<xsl:element name="li{count(ancestor::li) + 1}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>