xsl:analyze-string

The xsl:analyze-string element is new in XSLT 2.0. It applies a regular expression to a supplied string value. The string is split into a sequence of substrings, each of which is classified as either a matching substring (if it matches the regular expression) or a non-matching substring (if it doesn't). The substrings are then processed individually: the matching substrings by a xsl:matching-substring element that appears as a child of the xsl:analyze-string instruction, the non-matching substrings by a similar xsl:non-matching-substring element. If either of these is omitted, the relevant substrings are not processed.

The element has three attributes: select is an XPath expression whose value is the string to be analyzed; regex is the regular expression (which may be given as an attribute value template), and flags provides one or more Perl-like flags to control the way in which regular expression matching is performed, for example the value "m" indicates multi-line mode.

When processing matching substrings, it is possible to call the regex-group() function to find the parts of the matching substring that matched particular parenthesized groups within the regular expression.

There are examples of this element in the XSLT 2.0 Working Draft.