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

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

Namespace fixup is then applied, but this doesn't need to do anything, because all the required prefixes are already declared.

When the time comes to serialize this result tree, namespace nodes are used to generate namespace declarations. So the output (ignoring the XML declaration) should be this:


XSLT 2.0 (unlike 1.0) really doesn't give the implementation any latitude to generate anything else in this situation. In 1.0, there was a general rule that the serializer could add any namespace declarations it chose, and by implication that it could give elements and attributes any prefix that it chose. In 2.0, the namespace fixup process is only allowed to add namespaces if they are actually needed to make the tree consistent, and in this case, they aren't.

Example of

The following example generates an XSLT stylesheet consisting of a single global variable declaration, whose name and default value are supplied as parameters. Although this is a trivial stylesheet, it could be useful when incorporated into another more useful stylesheet using

or

.

This example is available in the code download as
alias.xsl
.

Source

No source document is required. You can run this with Saxon using the command:

java -jar c:\saxon\saxon9.jar -it:main -xsl:alias.xsl

The
-it
option on the command line causes the transformation to start at the template named
main
.

Stylesheet

                xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”

                xmlns:oxsl=“http://www.w3.org/local-alias”>

v



               stylesheet-prefix=“oxsl”

               result-prefix=“xsl”/>


   

   

      

   

   



Output

If you default the values of the parameters
variable-name
and
default-value
, the output is as follows.


                version=“1.0”>

   


See Also

Literal Result Elements
in Chapter 3, on page 112.

xsl:next-match

The

instruction allows more than one template rule to be applied to the same node in a source document. When

selects a node, it finds the best match template rule to process this node. Within this template rule, you can use the

instruction to invoke the next-best matching rule, and so on.

Changes in 2.0

This instruction is new in XSLT 2.0. It was introduced as an improved alternative to

, though that instruction remains available for backward-compatibility reasons.

Format


   


Position


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

Attributes

None.

Content

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

and/or

elements. An XSLT 2.0 processor will ignore the

instructions; they are allowed so that fallback behavior can be defined for use when the stylesheet is processed using an XSLT 1.0 processor. For details, see

on page 316.

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.


searches for a template rule that matches the current node, using the same search rules as

, but considering only those template rules that (a) match the current mode, and (b) have lower import precedence or priority than the current template rule. For details of import precedence, see

on page 359. If no template rule is found, the built-in template rule is used (see page 243).

There is a clear analogy here with object-oriented programming. Writing a template rule that overrides another is like writing a method that overrides a method defined on the superclass.

behaves analogously to the
super()
function in object-oriented programming languages, allowing the new template rule to refine the behavior of the original template rule, rather than replacing it completely.

Other books

Sweet Agony by Charlotte Stein
Claiming the Jackal by Glass, Seressia
A Sheetcake Named Desire by Jacklyn Brady
Dawn of the Dragons by Joe Dever
Broken Vows by Tom Bower
Deadly Holidays by Alexa Grace
Cates, Kimberly by Stealing Heaven