XSLT中的正则表达式模式匹配

时间:2014-05-14 09:02:17

标签: regex xslt

我有以下的XSL模板

<xsl:template match="para">
<xsl:analyze-string select="." regex="\d+(?=[-, \d]*$)">
        <xsl:matching-substring>
             <xsl:variable name="prent">
         <xsl:for-each select="document('C:\Users\u0138039\Desktop\Proview\SG\Commentary_SG_XML-03032014\SG-Singapore Precedents of Pleadings\title.xml')/entry/file">
                                   <xsl:value-of select="normalize-space(document(concat('C:\Users\u0138039\Desktop\Proview\SG\Commentary_SG_XML-03032014\SG-Singapore Precedents of Pleadings\',./@name))//chapter/title[//page/@num=regex-group(1)])"/>
</xsl:for-each>
                                </xsl:variable>
                                <xsl:variable name="cha">
                                    <xsl:value-of select="substring-before(substring-after($prent,'CHAPTER '),' ')"/>
                                </xsl:variable>    
<xsl:variable name="size">
<xsl:value-of select="string-length($cha)"/>
</xsl:variable>
<xsl:variable name="conct">
<xsl:choose>
    <xsl:when test="$size>'1'">
        <xsl:value-of select="concat('er:#SPPR_CH_',$cha,'/pg_',regex-group(1))"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="concat('er:#SPPR_CH_0',$cha,'/pg_',regex-group(1))"/>
    </xsl:otherwise>
</xsl:choose>
</xsl:variable>
 <a href="{$conct}">

        <xsl:value-of select="regex-group(1)"/>
 </a>
          </xsl:matching-substring>
          <xsl:non-matching-substring>
            <xsl:value-of select="."/>
          </xsl:non-matching-substring>
        </xsl:analyze-string>
</xsl:template>

以及XML

<para>this is 1989 representing text 245</para>
<para>this is sample text 235</para>
<para>this is 234 sample text with comma seperator 345,756</para>

当我运行它时,它会给我一个错误,如下所示。

Invalid regular expression '\d+(?=[-, \d]*$)' -   Details: -     XTDE1140: The effective value of the 'regex' attribute of the <xsl:analyze-string> instruction must conform to the required syntax for regular expressions

这里我想要实现的是,为了获得文本末尾的数字,忽略任何其他字符,当我测试正则表达式时,它工作正常。它是here,但是当我在我的XSLT中实现它时,它给我一个错误。

预期输出

<a href="245"/>
<a href="235"/>
<a href="345"/>,<a href="756"/>

请让我知道如何解决这个问题。

由于

0 个答案:

没有答案