分隔xslt的输出(在非平凡的情况下) [英] Delimiting the output for xslt (in non trivial cases)
本文介绍了分隔xslt的输出(在非平凡的情况下)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道在xsl转换中定界xml输出的最佳方法。
I would like to know the best way to delimit xml output in an xsl transform. "position() != last()" doesn't always work because it makes assumptions about the input.
此玩具示例演示:
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="//cd">
<xsl:if test="title !='Unchain my heart'">
<xsl:value-of select="title" />
<xsl:if test="position() != last()">
<xsl:text>; </xsl:text> <!-- sometimes the delimiter will end if last element is a duplicate; -->
</xsl:if>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
将导致
... Pavarotti Gala Concert; The dock of the bay; Picture book; Red;
注意结尾的分号。
任何
(此示例中的xml数据 http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog )
(xml data from this example http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog)
推荐答案
将其更改为:
<xsl:for-each select="//cd[title !='Unchain my heart']">
<xsl:value-of select="title" />
<xsl:if test="position() != last()">
<xsl:text>; </xsl:text>
</xsl:if>
</xsl:for-each>
或在XSLT 2.0中,
or in XSLT 2.0,
<xsl:value-of select="//cd/title[. !='Unchain my heart']" separator="; "/>
这篇关于分隔xslt的输出(在非平凡的情况下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文