Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The following example (
multiple-match.xsl
) blends these techniques. It analyzes an XPath expression and lists all the variable names that it references. The regex chosen is one that matches things you're interested in (the variable names), but it also uses parentheses to provide access to a captured group from which the leading
$
sign is left out. It's not an industrial-quality solution to this problem; for example, it doesn't try to ignore the content of comments and string literals. But it does allow for the fact that a space is permitted between the
$
sign and the variable name. You can extend it to handle these extra challenges if you like. (And if you are really keen, you can extend it to extract the namespace prefix from the variable name, and look up the corresponding namespace URI using the
get-namespace-uri-for-prefix()
function.)
Note in this example that a
$
sign used to represent itself must be escaped using a backslash, and that we are taking advantage of the rather specialized regex constructs
\i
and
\c
to match an XML name. The output is a sequence of
elements containing the names of the referenced variables.
See Also
matches()
on page 828 (Chapter 13)
replace()
on page 862 (Chapter 13)
tokenize()
on page 894 (Chapter 13)
regex-group()
on page 860 (Chapter 13)
Regular expression syntax, Chapter 14
xsl:apply-imports
The
There is a clear analogy here with object-oriented programming. Writing a stylesheet module that imports another is like writing a subclass, whose methods override the methods of the superclass.
super()
function in object-oriented programming languages, allowing the functionality of the superclass to be incorporated in the functionality of the subclass.
Changes in 2.0
In XSLT 2.0, the instruction is extended to allow parameters to be passed using enclosed
XSLT 2.0 also introduces a new
Format
Position
Attributes
None.
Content
The element may be empty, or it may contain one or more
Effect
current template rule
. A template rule becomes the current template rule when it is invoked using
Closely associated with this is the
current mode
. When a template rule is invoked using
instruction becomes the current mode (if no mode is named, then the default unnamed mode becomes the current mode). The current mode reverts to the default (unnamed) mode when a stylesheet function is called.