小编Mat*_*sta的帖子

如何实现XSLT tokenize函数?

似乎EXSLT tokenize函数不适用于PHP XSLTProcessor(XSLT 1.0).

我试图在纯XSL中实现它,但我不能使它工作:

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:func="http://exslt.org/functions"
    xmlns:exsl="http://exslt.org/common"
    xmlns:my="http://mydomain.com/">

    <func:function name="my:tokenize">
        <xsl:param name="string"/>
        <xsl:param name="separator" select="'|'"/>
        <xsl:variable name="item" select="substring-before(concat($string,$separator),$separator)"/>
        <xsl:variable name="remainder" select="substring-after($string,$separator)"/>
        <xsl:variable name="tokens">
            <token><xsl:value-of select="$item"/></token>
            <xsl:if test="$remainder!=''">
                <xsl:copy-of select="my:tokenize($remainder,$separator)"/>
            </xsl:if>
        </xsl:variable>
        <func:result select="exsl:node-set($tokens)"/>
    </func:function>

    <xsl:template match="/">
        <xsl:copy-of select="my:tokenize('a|b|c')"/>
    </xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

预期结果 :

    <token>a</token><token>b</token><token>c</token>
Run Code Online (Sandbox Code Playgroud)

实际结果 :

    abc
Run Code Online (Sandbox Code Playgroud)

我知道这个问题已被多次发布,但我找不到简单的解决方案.

谢谢您的帮助.

php xml xslt tokenize

4
推荐指数
1
解决办法
8724
查看次数

标签 统计

php ×1

tokenize ×1

xml ×1

xslt ×1