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

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

Examples

This example imports the schema for namespace
http://ns.megacorp.com/hr
from the location
http://schema.megacorp.com/hr/schema.xsd
:

    namespace = “http://ns.megacorp.com/hr”

    schema-location = “http://schema.megacorp.com/hr/schema.xsd”/>

The following example imports a no-namespace schema from the file
schema.xsd
in the same directory as the stylesheet:

    schema-location = “schema.xsd”/>

The following example imports the schema that defines the structure of XSLT stylesheets. (This import would be useful only in a stylesheet that is designed to process XSLT stylesheets as its input and/or result documents.).

    namespace = “http://www.w3.org/1999/XSL/Transform”

    schema-location=“http://www.w3.org/2007/schema-for-xslt20.xsd”/>

The following example defines a union type for use locally within the stylesheet. This type allows either an
xs:date
, an
xs:time
, or an
xs:dateTime
:


  

    

      

    

  


This type might be used in the signature of a function that applies default formatting to the value, as follows:


  

  

  

    

      

    

    

      

    

    

      

    

  


The full stylesheet is in file
inline.xsl
. Unfortunately it's not possible to use the union type directly as a parameter to the function (
as=“local:dateOrTime”
) — although the meaning is intuitive, union types cannot appear directly in a
SequenceType
, only as a type annotation on element or attribute nodes.

xsl:include


is a top-level element used to include the contents of one stylesheet module within another. The definitions in the included stylesheet module have the same
import precedence
as those in the including module, so the effect is as if these definitions were textually included at the point in the including module where the

element appears.

Changes in 2.0

There are no changes to the syntax of this instruction in XSLT 2.0. The rules for the
href
attribute have been reformulated to reflect current practice with XSLT 1.0: In effect, the way in which the URI is dereferenced to obtain a stylesheet module is now largely implementation defined. This allows for options such as catalogs or user-specified URI resolvers, as well as implementations that cache or precompile stylesheet modules.

Format

  href = uri-reference />

Position


is a top-level declaration, which means that it must appear as a child of the

element. There are no constraints on its ordering relative to other declarations in the stylesheet.

Attributes

Name
Value
Meaning
href
mandatory
URI
The URI of the stylesheet to be included

Like all other XSLT elements, the

declaration may also have a
use-when
attribute. This is described in Chapter 3 (see page 127). This can be used in the same way as on

: see the example on page 358.

Other books

The Sorcerer's Bane by B. V. Larson
Pirate King by Laurie R. King
The Devil's Interval by Linda Peterson
Girl, Stolen by April Henry
Psion by Joan D. Vinge
Scream for Me by Cynthia Eden
Angel Of The City by Leahy, R.J.