FORX0003:tokenize()中的正则表达式不能与零长度字符串匹配

use*_*877 0 xslt

嗨,这适用于","和其他分隔符,但它不适用于PIPE(|)符号只有它给FORX0003:tokenize()中的正则表达式不能与零长度字符串匹配

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template> 
<xsl:template match="text/text()" name="tokenize">
    <xsl:param name="separator" select="'|'"/>
    <xsl:for-each select="tokenize(.,$separator)">
        <item>
            <xsl:value-of select="normalize-space(.)"/>
        </item>
    </xsl:for-each>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

Nav*_*wat 5

如果你想从'|'标记化,你只需要替换<xsl:param name="separator" select="'|'"/><xsl:param name="separator" select="'\|'"/>字符.看看我的示例XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="text">Navin | Rawat</xsl:param>
<xsl:param name="separator" select="'\|'"/>

  <xsl:template match="/">
  <xsl:for-each select="tokenize($text,$separator)">
    <item>
      <xsl:value-of select="normalize-space(.)"/>
    </item>
  </xsl:for-each>
  </xsl:template>

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

OUTPUT:

<item>Navin</item><item>Rawat</item>
Run Code Online (Sandbox Code Playgroud)