xsl:analyze-string

Applies a regular expression to a supplied string value.

Category: instruction
Content: ( xsl:matching-substring? , xsl:non-matching-substring? , xsl:fallback* )
Permitted parent elements: any XSLT element whose content model is sequence constructor; any literal result element

Attributes

select

expression

XPath expression whose value is the string to be analyzed.

regex

{ string }

The regular expression, which may be given as an attribute value template.

flags?

{ string }

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.

Notes on the Saxon implementation

XSLT 3.0 removes the restriction that the regular expression must not be one that matches a zero-length string, so this is now allowed in Saxon 9.6.

Details

The xsl:analyze-string element 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.

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.

Examples

Examples of this element can be found in the XSLT 3.0 Recommendation.

Links to W3C specifications

XSLT 2.0 Specification

XSLT 3.0 Specification

See also

xsl:matching-substring

xsl:non-matching-substring

matches()

replace()

tokenize()

regex-group()