开发者

Pattern Matching with XSLT

开发者 https://www.devze.com 2023-01-03 06:04 出处:网络
I\'m trying to match a pattern into a string in XSLT/XPath using the matches function, as follows: <xsl:when test=\"matches(\'awesom开发者_StackOverflow中文版e\',\'awe\')\">

I'm trying to match a pattern into a string in XSLT/XPath using the matches function, as follows:

<xsl:when test="matches('awesom开发者_StackOverflow中文版e','awe')">
   ...
</xsl:when>

However, in both Firefox 3.5.9 and IE8, it doesn't show up. IE8 tells me that "'matches' is not a valid XSLT or XPath function." Is this due to XSLT 2.0 not being supported, and is there a way around this?


Regular Expressions are supported only in XSLT 2.x/XPath 2.x.

As at this date, no publicly available browser supports XSLT 2.x/XPath 2.x.

In your concrete case you can use:

starts-with('awesome','awe')

other useful XPath 1.0 functions are:

  • contains()

  • substring()

  • substring-before()

  • substring-after()

  • normalize-space()

  • translate()

  • string-length()


In addition to the correct hint that browsers don't support XSLT/XPath 2.0: note that Firefox (since version 3.0 I think) supports some EXSLT functions, in particular for regular expressions: https://developer.mozilla.org/en/EXSLT#Regular_expressions so with Firefox you could consider EXSLT functions. For IE using MSXML you could incorporate http://exslt.org/regexp/functions/match/regexp.match.msxsl.xsl which implements the EXSLT match function using the msxsl:script element.

0

精彩评论

暂无评论...
验证码 换一张
取 消