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

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

The
type
attribute gives the required type of the document element (not the document node). For example, if
type=“mf:invoiceType”
is specified, then the single element child of the document node is validated against the schema type
mf:invoiceType
.

Usage and Examples

The most likely reason for using

is to invoke validation of a temporary tree.

It is possible to perform element-level validation of the document element in a tree without using

, for example by writing:


  

    

  


However, this does not perform document-level validation: it doesn't check the
ID
and
IDREF
constraints defined in the schema, for example. To perform these extra checks, it is necessary to write the

instruction explicitly:


  

    

      

    

  


There are certain other situations where

might be needed. For example, this is the only way of producing a sequence containing several new document nodes. It is also necessary if you want the value of a variable, or the default value of a parameter, to be a document node, and you also want to use the
as
attribute of

or

to define the type of the variable, for example
as=“document(element(*, mf:invoiceType))”
.

See Also


on page 445


on page 386

xsl:element

The

instruction is used to create an element node and write it to the result sequence. It provides an alternative to using a literal result element and is useful especially when the element name or namespace is to be calculated at runtime.

Changes in 2.0

Two new attributes
validation
and
type
are available, to control whether and how the copied nodes are validated against a schema.

Format

  name = { qname }

  namespace? = { uri-reference}

  use-attribute-sets? = qnames

  inherit-namespaces? = “yes” | “no”

  validation? = “strict” | “lax” | “preserve” | “strip”

  type? = qname>

  


Position


is used as an instruction within a sequence constructor.

Attributes

Name
Value
Meaning
name
mandatory
Attribute value template returning a lexical QName
The name of the element to be generated.
namespace
optional
Attribute value template returning a URI
The namespace URI of the generated element.
use-attribute-sets
optional
Whitespace-separated list of lexical QNames
List of named attribute sets containing attributes to be added to this output element.
inherit-namespaces
optional
yes
or
no
. (Default is
yes
).
Indicates whether the namespaces of the constructed element will be inherited by its children.
validation
optional
strict
,
lax
,
preserve
, or
skip
Indicates whether and how the element should be subjected to schema validation, or whether existing type annotations on attributes and child elements should be retained or removed.
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
4.07Mb size Format: txt, pdf, ePub
ads

Other books

Zorba the Hutt's Revenge by Paul Davids, Hollace Davids
My Lady Rival by Ashley March
The Sorceress by Michael Scott
The Kings of London by William Shaw
Scornfully Hers by Pamela Ann
The CV by Alan Sugar
La última concubina by Lesley Downer