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

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

Copying Type Annotations

The
validation
attribute of the

instruction gives you four options on how to handle type annotations:

  • The
    strip
    option removes all type annotations from the element and attribute nodes being copied, leaving them only with the generic type annotations
    xs:untyped
    and
    xs:untypedAtomic
    , respectively. The main advantage of doing this is that you know exactly where you stand. This is the default, unless overridden using the
    default-validation
    attribute of the

    element, and it means that the behavior will be the same whether or not the processor is schema-aware.
  • Sometimes the
    strip
    option is needed because the existing type annotations do not make sense in a new context. For example, you might be copying a
    price-range
    attribute from an element in which the name is constrained to be a sequence of two numbers, to an element in which any string is allowed. Retaining the type annotation would cause spurious effects, or errors, if the attribute in its new context is then used for comparisons or sorting.
  • The
    preserve
    option leaves all the type annotations intact. One might expect that this would be the default, but the value
    strip
    was chosen for consistency with other instructions. Generally speaking, if the source nodes have been validated and annotated, this will often be the option that makes most sense on

    .

    This option works because the validity of an element or attribute depends only on its content (that is, on its attributes, its descendant elements, and their attributes). Cross-validation constraints such as
    ID/IDREF
    constraints are not taken into account by the XPath type system. This means that if the source data has a particular type annotation, you can take it on trust that the data is valid against that type, and if you copy the whole subtree, then the new nodes will still be valid against these types.

  • The
    strict
    and
    lax
    options discard all existing type annotations, and then invoke the schema processor to validate the copied nodes. The same happens when you use the
    type
    attribute instead of the
    validation
    attribute. The way that validation works is exactly as described for the

    instruction in the case of element nodes (see page 312), or the

    instruction in the case of attribute nodes (see page 258), or the

    instruction in the case of document nodes (see page 304). For other nodes and atomic values the
    validation
    and
    type
    attributes are ignored.

Other books

Mona and Other Tales by Reinaldo Arenas
True Stories by Helen Garner
1,227 QI Facts to Blow Your Socks Off by John Lloyd, John Mitchinson
Thief by Greg Curtis
Corazón de Ulises by Javier Reverte
Loralynn Kennakris 3: Asylum by Owen R. O'Neill, Jordan Leah Hunter
Woof at the Door by Laura Morrigan