EXSL - 如何使用 str:tokenize()?

问题描述:

我刚开始使用 XSLT,我尝试在 XSLT 1.0 中使用 str:tokenize() 模板.我查了一下:http://www.exslt.org/str/functions/tokenize/index.html

I'm just starting XSLT and I try to use the str:tokenize() template in XSLT 1.0. I checked on: http://www.exslt.org/str/functions/tokenize/index.html

但我无法得到预期的结果.

But I can't get the expected result.

这是代码:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                xmlns:exsl="http://exslt.org/common"
                                xmlns:str="http://exslt.org/strings"
                                exclude-result-prefixes="str">
<xsl:output method="xml"/>
<xsl:template match="/">
  <xsl:variable name="var" select="John.Wayne"/>
    <root>
       <xsl:for-each select="str:tokenize($var,'.')">
            <element>
                <xsl:value-of select="."/>
            </element>
        </xsl:for-each>
    </root>
</xsl:template>
</xsl:stylesheet>

我的预期输出应该是:

  <root>
     <element>John</element>
     <element>Wayne</element>
    </root>

任何帮助表示赞赏.提前致谢!哦,顺便说一句,我的输出是:

Any help appreciated. Thanks in advance! Oh, by the way, my output is:

<?xml version="1.0"?>
<root/>

(我使用的是 xsltproc)

(I'm using xsltproc)

<xsl:variable name="var" select="John.Wayne"/>

正在将 XPath John.Wayne 的评估结果分配给 var.

is assigning to var the result of the evaluation of the XPath John.Wayne.

要将var 分配给字符串值 John.Wayne,您必须用单引号将其括起来:

To assign to var the string value John.Wayne you have to surround it with single quotes:

<xsl:variable name="var" select="'John.Wayne'"/>