dpkpaxhzffixp8426 2010-08-10 19:44
浏览 49
已采纳

xslt正则表达式匹配xml条目并显示

I know it is so simple to some of you.

All I want to do is look through an xml doc and print out the xml entries that contain specific string fragments. The string value is passed to the xslt and the xml doc is looked at and if a word begins with the string expression it displays it.

What I have errors with the following message...

MM_XSLTransform error: Error while transforming: 'matches()' is an unknown XSLT function.

here is my code sample...

<xsl:stylesheet 
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">
  <xsl:output method="html" encoding="utf-8"/>
  <xsl:param name="qString" />
  <xsl:template match="/">
    <xsl:for-each select="Products/Product">

        <xsl:if test="matches('/OldPN','$qString')">
          <xsl:value-of select="OldPN" /> - <xsl:value-of select="OldName" />
        </xsl:if>

    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Any ideas? Would so appreciate help on this!

  • 写回答

3条回答 默认 最新

  • douyao3895 2010-08-10 20:09
    关注

    The matches function for regular expressions is new in xslt 2.0, which is probably not yet supported by your xslt processor. If you can use a plain string instead of a regular expression you can try either contains or starts-with instead.

    In addition, in your example the second parameter must not be enclosed in quotes, since then you would be matching against the literal string "$qString" instead of the value of this parameter.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料