Templates XSLT和属性中的数字
我有这样一个xml片段:Templates XSLT和属性中的数字,templates,xslt,attributes,numbers,Templates,Xslt,Attributes,Numbers,我有这样一个xml片段: <p rend="noIndent">eget <seg type="comStart" n="com123"/>kunde<seg type="comEnd" n="com123"/> der i Anledning af disse <seg type="comStart" n="com13"/>kunde<seg type="comEnd" n="com13"/> Smaadigte være at s&
<p rend="noIndent">eget <seg type="comStart" n="com123"/>kunde<seg type="comEnd" n="com123"/> der i Anledning af disse <seg type="comStart" n="com13"/>kunde<seg type="comEnd" n="com13"/> Smaadigte være at s</p>
在s
我想更改n属性中的数字,使数字以1开头。对于类型属性中的每对comStat和comEnd,n-attribute中的值应相同,结果如下:
<p rend="noIndent">eget <seg type="comStart" n="com1"/>havde<seg type="comEnd" n="com1"/> der i Anledning af disse <seg type="comStart" n="com2"/>kunde<seg type="comEnd" n="com2"/> Smaadigte være at s</p>
在s
如何匹配xslt中相应的n属性
KSR如果始终存在对,您可以使用
xsl:number
为comStart
元素创建数字:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="*[@type = ('comStart', 'comEnd')]/@n">
<xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
N
分别
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[@type = 'comStart' or @type = 'comEnd']/@n">
<xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
N
对于XSLT 1()。如果始终存在对,则可以使用
xsl:number
为comStart
元素创建数字:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="*[@type = ('comStart', 'comEnd')]/@n">
<xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
N
分别
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[@type = 'comStart' or @type = 'comEnd']/@n">
<xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
N
对于XSLT1()