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

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

Usage

Character maps are useful in many situations where you need precise control over the serialization of the result tree.

In general, if you are producing XML output that is to be used by another application, or if you are producing HTML output that is destined to be displayed in a browser, then the standard serialized output should be perfectly adequate. The situations where you need a finer level of control are typically:

  • If the output is designed to be edited by humans rather than processed by a machine. In this case, you may want, for example, to control the use of entity references in the output.
  • If you need XML output containing an internal DTD subset within the document. Generate the DTD as text, using characters such x2039 and x2040 (left/right-pointing angle bracket) as substitutes for
    <
    and
    >
    .
  • If the output format is not standard HTML or XML, but some proprietary extension with its own rules. Such dialects are commonly encountered with HTML, though fortunately they are very rare in the case of XML. A similar requirement arises where the required output format is SGML.
  • If the application that processes the HTML or XML that you produce is buggy. You live in the real world and life isn't perfect. For example, it is rumored that some very old browsers will not accept an
    &
    in a URL that has been escaped as
    &
    , even though the HTML standard requires the escaped form. If you encounter such bugs, you may need to work around them.
  • If the required output format uses what I call
    double markup
    . By this I mean the use of XML tags in places where tags are not recognized by an XML parser, generally within
    CDATA
    sections or comments. I don't think that this is a particularly good design pattern for XML, because it is not possible to model the structure correctly as a tree using the XPath data model, but document structures such as this exist and you may be obliged to produce them. You can solve this problem using character maps by choosing two characters to map to the CDATA start and end delimiters (
    and
    ]]>
    ) or the comment start and end delimiters (

    ). An example is shown on page 943.

Other books

What Would Mr. Darcy Do? by Abigail Reynolds
The Dog by Cross, Amy
Night and Day by White, Ken
When We Collide by A. L. Jackson
Margaret Truman by The President's House: 1800 to the Present : The Secrets, History of the World's Most Famous Home