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

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

You can't set the default to
strict
or
lax
. Allowing the value
strict
would give you problems unless every element and attribute that you create were declared globally in a schema, which would be unusual. Allowing
lax
would be more likely to give acceptable results, but could lead to performance problems through excessive validation.

The default value for the
default-validation
attribute is
strip
. Personally, I would stick with this default. Changing it to
preserve
may lead to rather patchy results in terms of which elements and attributes carry a type annotation, and which are left as untyped. Preserving type annotations makes most sense when you are explicitly copying data from one document to another, and it's probably best to request it explicitly on the instructions that do the copying.

But there may well be situations I haven't thought of, and if you find yourself using the same value of the
validation
attribute throughout the stylesheet, then defining a default at the stylesheet module level may turn out to be a useful thing to do.

Importing Schemas

The facilities that we've been discussing in this chapter work only if schema information is available to the XSLT processor. The primary way that the processor gets this information is through the

declaration, which can be used at the top level of any stylesheet module.

The

declaration is modeled on the

element within the XML Schema specification, but with some concessions to the XSLT house style (for example, the
schemaLocation
attribute in

becomes
schema-location
in XSLT). Importantly, it adopts the same deliberate vagueness about exactly where the schema comes from, giving implementations the freedom to implement local schema caches or catalogs.

The most important attribute is the
namespace
attribute. This gives the target namespace of the schema being imported. If the attribute is omitted, this represents a request for a schema with no target namespace. You should import a schema for each namespace that contains a type definition, element declaration, or attribute declaration that your stylesheet refers to by name. Importing a schema that in turn imports another schema isn't good enough: The only names that become available for use in your stylesheet are those in namespaces that you import explicitly. The XSLT processor is given some leeway to implicitly import schemas that aren't requested explicitly in the stylesheet. This is intended particularly for use in highly controlled environments, such as running a transformation within an XML database engine where the available schemas are all known in advance. But it's unwise to rely on this if you want your stylesheet to be portable.

Other books

Liquidate Paris by Sven Hassel
Grimscribe by Thomas Ligotti
Me Without You by Rona Go
Hungry Heart: Part Two by Haze, Violet
Stripped Down by Emma Hart
The Big Fight by Sugar Ray Leonard
Triple Threat by Jeffery Deaver