XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (126 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
2.23Mb size Format: txt, pdf, ePub

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


on page 386


on page 402

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

instruction is used in conjunction with imported stylesheets. A template rule in one stylesheet module can override a template rule in an imported stylesheet module. Sometimes, you want to supplement the functionality of the rule in the imported module, not to replace it entirely.

is provided so that the overriding template rule can invoke the overridden template rule in the imported module.

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.

behaves analogously to the
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

elements.

XSLT 2.0 also introduces a new

instruction, which will often be a more suitable solution in situations where

might have previously been used.

Format


  


Position


is an instruction, and it is always used within a sequence constructor.

Attributes

None.

Content

The element may be empty, or it may contain one or more

elements.

Effect


relies on the concept of a
current template rule
. A template rule becomes the current template rule when it is invoked using

,

, or

. Using

does not change the current template rule. However, using

makes the current template rule null, until such time as the

terminates, when the previous value is reinstated. The current template rule is also null while global variables and attribute sets are being evaluated.

Closely associated with this is the
current mode
. When a template rule is invoked using

, the mode specified on the

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.

Other books

Maelstrom by Jordan L. Hawk
Snow Wolf by Meade, Glenn
Bones & All by Camille DeAngelis
Life as We Knew It by Susan Beth Pfeffer
The Dream Merchants by Harold Robbins
The Cause by Roderick Vincent
Forever Love (Fghter Club 1) by Marie Dominique