2013-05-21 29 views
0

嗨,这适用于“,”和其他分隔符,但它不适用于PIPE(|)符号只有它给予FORX0003:在令牌化()的正则表达式不能是一个零长度字符串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> 

+0

能否请您短语以更清晰的方式问题吗? –

+0

也许问题在于,呃,tokenize()中的正则表达式不能是匹配零长度字符串的正则表达式。 “'|'”如何匹配零长度的字符串?因为它是两个零长度字符串之间的替代方案。 – 2013-05-21 04:41:49

回答

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> 

OUTPUT:

<item>Navin</item><item>Rawat</item> 
相关问题