3

I know that lookahead pattern is not allowed in XSLT with saxon, but I need to know how I can use this regular expression in XSLT 2.0:

    <xsl:if test='matches($value,"^(?!\s*$).{x,y}$")'>

where x and y are numbers. Any suggestions please?

  • http://saxonica.com/html/documentation/functions/fn/matches.html explains that you can use the flags `j` and `n`, where `j` enables the regular expression syntax supported by the Java platform and `n` the one supported by the .NET platform (only with the .NET version of Saxon). So depending on the version of Saxon you use try to check whether the platform's regular expression format supports that lookahead pattern and use the flag to enable it. – Martin Honnen Jul 17 '17 at 18:38

1 Answers1

4

According to https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html the Java language supports e.g. (?!X) as X, via zero-width negative lookahead so you should be able to enable it with Saxon using the flag ;j', as in matches(string, '(?!subpattern1)subpattern2', ';j') as Saxon allows you (http://saxonica.com/html/documentation/functions/fn/matches.html) to switch to the Java regular expression language using that flag.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110