[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Re: Pattern-Matching / Regular Expression Types

Subject: [xsl] Re: Pattern-Matching / Regular Expression Types
From: Tiago Freitas <coolkcah@xxxxxxxxx>
Date: Thu, 26 Apr 2012 23:04:16 +0100

Michael Kay suggested (on stackoverflow) some possibilities:

(a) if the sequence of nodes you are matching is the sequence of
children of some parent node, then you can recast this as a rule for
matching the parent node

(b) convert the structural information that you want to match on into
a string, and use regular expression matching to assess the string

(c) write XSD complex type definitions for the grammar that you want
to match, and use the XSLT validate-by-type capability (in conjunction
with XSLT 3.0's try/catch) to test whether the sequence of nodes
matches a named complex type in the schema.

Method a) I'm not sure yet how it could be done.

Method b) (same Wendell suggested) is possible for the matching, but
then I can't save the nodes for further manipulation, and it's harder
to add functionality.

Method c) uses XSLT 3.0 functionality, and I would like to avoid it,
since I would need a license for most processors (student with no


I found the op:node-before function / << operator, that I think could
be used for this.
For example, to represent the * in my pattern examples, I would get
all the nodes after the preceding and before the following path to the
*. This way I would keep restricting the nodeset with the order in the
pattern. This does not seem efficient...

Other possible paths:

I found XDuce, another XML processing language, that has native regex
patterns and regex types that seem better suited for this, but there
are no implementations for Java that I could find, and I would prefer
to use a W3C standard if there is a good method.
XDuce has ML, OCaml, and C# (XTatic) implementations that could work.
XRel is a very limited Java implementation (no attributes support).
I read somewhere that the XQuery definition was based on XDuce, but
the regex pattern matching does not seem to be exposed.

I also found XACT and schematools for Java, based on "XML
Graphs"/"Summary Graphs", but it's clear how to apply it.

Scala has native XML processing with pattern matching; does not seem
as powerful as XDuce, but seems a good option.

Current Thread