Xslt在标记化数组中选择剩余标记

时间:2013-05-20 19:28:13

标签: html xml templates xslt token

在我的Xsl文档中,我需要创建一个包含换行符的文本链接,创建两个句子。

我正在使用tokenize通过拆分空格字符来添加单词。

<xsl:variable name="tokens" select="tokenize($sentece, '\s+')"></xsl:variable>

第一句话将包含三个单词,只需选择$tokens[1] $tokens[2] $tokens[3] <br />

即可

现在,如何在tokenize数组中选择任意数量的剩余单词?是否可以在$ tokens数组上执行for循环?

1 个答案:

答案 0 :(得分:1)

您可以执行for-each并查看position() > 3这样的内容......

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:variable name="sentance">The first sentance. The second...</xsl:variable>
    <xsl:variable name="tokens" select="tokenize($sentance, '\s+')"/>

    <xsl:for-each select="$tokens">
      <xsl:if test="position() > 3">

        <xsl:value-of select="."/>

        <xsl:if test="position() != last()">
          <xsl:text> </xsl:text>
        </xsl:if>
      </xsl:if>
    </xsl:for-each>

  </xsl:template>
</xsl:stylesheet>

...输出

The second...
相关问题