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

时间:2013-05-21 03:01:07

标签: 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>

1 个答案:

答案 0 :(得分: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>

<强>输出:

<item>Navin</item><item>Rawat</item>