我想选择第一个元素并使用@type='first'
,最后一个元素@type='last'
,拳头和最后一个元素之间的元素@type='middle'
输入:
<disp-quote>
<p>Text 1</p>
<p>Text 2</p>
<p>Text 3</p>
<p>Text 4</p>
</disp-quote>
所需的输出:
<p type="first">Text 1</p>
<p type="middle">Text 2</p>
<p type="middle">Text 3</p>
<p type="last">Text 4</p>
试过的代码:
<xsl:template match="disp-quote/p">
<p>
<xsl:attribute name="type">
<xsl:value-of select="self:p/position()"/>
</xsl:attribute>
<xsl:apply-templates/>
</p>
</xsl:template>
但是输出没有按预期工作。请帮助解决这个问题。谢谢你。我正在使用 XSLT 2.0
为什么不简单:
<p>
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="position()=1">first</xsl:when>
<xsl:when test="position()=last()">last</xsl:when>
<xsl:otherwise>middle</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</p>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句