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

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

,

, and

to prevent this happening. However, character references such as this are recognized only if the XPath expression is preprocessed by an XML parser. They are not recognized when the expression is written as a string in a Java or C# program.

Examples

The following examples assume XPath is being used in a freestanding environment with no need to escape special characters:

Expression
Description
“John's”
The string
John's
‘“’
A string consisting of a single character, the double quotation mark
‘O’‘Reilly’
The string
O'Reilly

The following examples assume that XPath expressions are contained in an attribute within an XML document; for example, an XSLT stylesheet:

XSLT Attribute
Description
select=“‘John’‘s’”
The string
John's
. The character used as the string delimiter can be escaped by doubling it.
select=“‘"’”
A string consisting of a single character, the double quotation mark. The character used as the XML attribute delimiter can be escaped by using an XML entity or character reference.
select=“‘Don’‘t say "yes"’”
The string
Don't say “yes”
. This combines the two escaping techniques from the previous examples.

Changes in XPath 2.0

The ability to include the string-delimiter character within the string by doubling it is new in XPath 2.0. The convention has been adopted from SQL and has the advantage of being backward-compatible with XPath 1.0.

XSLT Usage

Handling the two kinds of quotation marks in XPath expressions written within stylesheets can be tricky, even with the new escape convention introduced in XPath 2.0. You can often circumvent the problems (and produce clearer code) by using variables. For example, instead of writing:


   …


write instead:


  Don't say “yes”



  …


Other books

Silver by Steven Savile
Billionaire's Threat by Storm, Sloan
Antes bruja que muerta by Kim Harrison
Bare Witness by Katherine Garbera
Kissing Kate by Lauren Myracle
The Death Dealers by Mickey Spillane
The Finkler Question by Howard Jacobson
Swift Runs The Heart by Jones, Mary Brock
Death of a Dreamer by Beaton, M.C.