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

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

This stylesheet demonstrates a mixture of rigidly structured data processed using

instructions, sometimes called
pull
processing, and narrative markup processed using

instructions, referred to as
push
processing. The great advantage of the
push
approach is that the rules are written making no assumptions about the way the markup tags are nested in the source document. It is very easy to add new rules for new tags and to reuse rules if an existing tag is used in a new context.

Where the nesting of elements is more rigid, this very flexible rule-based style of processing has fewer benefits, so the
pull
programming style using

in conjunction with conventional flow-of-control constructs such as

,

, and

is often used. For further discussion of the different design approaches, see Chapter 17.

Using Modes

The classic reason for using modes is to enable the same content to be processed more than once in different ways; for example, the first pass through the document might generate the table of contents, the second pass the actual text, and the third pass an index.

Example: Using modes

The source document is a concert review in the same format as in the previous example. This time, however, the requirement is to produce at the end of the review a list of works mentioned in the text.

Source

The source file is
review.xml
. See previous example.

Stylesheet

The stylesheet file is
review + index.xsl
.

This stylesheet extends the previous one using

. After outputting the text as before, it now creates a table listing the works mentioned in the text. Note the use of an empty template rule with
match=“text()”
to ensure that when the text is processed with
mode=“index”
, nothing is output. The only output comes from the template rule that matches

elements.

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



  

  Index of Works

  

  ComposerTitle

      Opus

  

  




    

      

      

    

      



Output

The output is as shown in
Figure 6-15
.

See Also


on page 240


on page 237


on page 271

generate-id()
function in Chapter 7, on page 797

xsl:text

The

instruction is used within a sequence constructor to output literal text to the result sequence. The main purpose of wrapping an

element around literal text is to control the output of whitespace.

Changes in 2.0

None.

Format

  disable-output-escaping? = “yes” | “no”>

  


Position


is an instruction. It is always used as part of a sequence constructor.

Attributes

Name
Value
Meaning
disable-output-escaping
optional, deprecated
yes
or
no
The value
yes
indicates that special characters in the output (such as
<
) should be output as is, rather than using an XML escape form such as
<
. The default value is
no
.
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
8.76Mb size Format: txt, pdf, ePub
ads

Other books

Taboo Kisses by Gracen Miller
Promise to Obey by Whitelaw, Stella
Smoke & Mirrors by John Ramsey Miller
Jagged Edge by Mercy Cortez
She Wore Red Trainers by Na'ima B. Robert
Last Lawman (9781101611456) by Brandvold, Peter
Hot Spot by Susan Johnson
The Boy Who Harnessed the Wind by William Kamkwamba