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
4.87Mb size Format: txt, pdf, ePub
ads

,

, 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”



  …


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

Other books

The Threshold Child by Callie Kanno
Sacred Revelations by Harte Roxy
Finding Chase (Chasing Nikki) by Weatherford, Lacey