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

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

It is an error if the resulting sequence contains an attribute or namespace node.

Finally, the nodes in the sequence are attached to the new document node as its children. Officially, this involves making a deep copy of each node: This is because nodes in the data model are immutable, so you cannot change the parent of an existing node. In practice, making a copy at this stage is very rarely necessary, because in most cases the node being attached has only just been created and will never be used independently of its new parent. The only case where it is necessary is where the result sequence contains references to existing nodes, which can be produced using the

instruction:


   


Even in this case, creating new nodes can be avoided if the result tree is to be immediately serialized.

Validating and Annotating the Document

The
validation
and
type
attributes control whether and how the new document is validated. They are available only if you are using a schema-aware processor. As usual, validation has two effects: it triggers a failure if the result document is invalid according to the schema, and it creates type annotations on the nodes in the tree.

The
validation
attribute has the same four values as on other elements:
strip
,
preserve
,
strict
, and
lax
. If the
validation
attribute is not specified, then the default is provided by the
default-validation
attribute on the

element, which in turn defaults to
strip
.

  • strip
    removes all type annotations, replacing them with
    xs:untyped
    for elements and
    xs:untypedAtomic
    for attributes.
  • preserve
    leaves the type annotations as they are, determined by the
    validation
    and
    type
    attributes on the instructions that created individual elements and attributes.
  • strict
    and
    lax
    firstly check that the tree represents a well-formed XML document, that is, that the children of the document node comprise exactly one element node, no text nodes, and any number of comments and processing instructions. If not, a failure is reported. Then the top-level element node (the document element) is validated against the schema definitions, with the difference being that
    lax
    validates an element only if a schema definition for that element can be found, while
    strict
    fails if no declaration of this element can be found.
  • Validation of a document node works in the same way as validation of individual elements but with one important exception: ID/IDREF constraints defined in the schema are checked when validation is done at the document level but not when it is done at element level. This involves checking that
    xs:ID
    values are unique and that
    xs:IDREF
    and
    xs:IDREFS
    values reference an ID value somewhere in the document.
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
2.04Mb size Format: txt, pdf, ePub
ads

Other books

Betina Krahn by The Unlikely Angel
Sugar Rush by McIntyre, Anna J.
Maritime Murder by Steve Vernon
Smoldering Desire by Desiree Day
Silent Night by Natasha Preston
Complete Nothing by Kieran Scott
Snow White Must Die by Nele Neuhaus