我正在尝试使用 match 函数将模式匹配到 XSLT/XPath 中的字符串,如下所示:
<xsl:when test="matches('awesome','awe')">
...
</xsl:when>
但是,在 Firefox 3.5.9 和 IE8 中,它都没有出现。IE8 告诉我“'matches' 不是有效的 XSLT 或 XPath 函数”。这是因为不支持 XSLT 2.0,有没有办法解决这个问题?
我正在尝试使用 match 函数将模式匹配到 XSLT/XPath 中的字符串,如下所示:
<xsl:when test="matches('awesome','awe')">
...
</xsl:when>
但是,在 Firefox 3.5.9 和 IE8 中,它都没有出现。IE8 告诉我“'matches' 不是有效的 XSLT 或 XPath 函数”。这是因为不支持 XSLT 2.0,有没有办法解决这个问题?
正则表达式仅在 XSLT 2.x/XPath 2.x 中受支持。
截至目前,没有公开可用的浏览器支持 XSLT 2.x/XPath 2.x。
在您的具体情况下,您可以使用:
starts-with('awesome','awe')
其他有用的 XPath 1.0 函数是:
contains()
substring()
substring-before()
substring-after()
normalize-space()
translate()
string-length()
除了浏览器不支持 XSLT/XPath 2.0 的正确提示之外:请注意 Firefox(我认为是 3.0 版起)支持一些 EXSLT 函数,特别是对于正则表达式:https ://developer.mozilla.org/en/ EXSLT#Regular_expressions因此使用 Firefox 您可以考虑使用 EXSLT 函数。对于使用 MSXML 的 IE,您可以合并http://exslt.org/regexp/functions/match/regexp.match.msxsl.xsl,它使用 msxsl:script 元素实现 EXSLT 匹配功能。