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

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

Examples

Let's try to put these different forms into context by seeing how they can be used with a real schema. I'll use as my example the schema for XSLT 2.0 stylesheets, which is published in an appendix of the XSLT 2.0 specification at
http://www.w3.org/TR/xslt20
. This example is therefore relevant if you are using XPath expressions to access an XSLT 2.0 stylesheet (which is not as esoteric a requirement as you might think), and it also assumes that the XSLT 2.0 stylesheet has been validated against this schema.

The schema starts with a couple of complex type definitions like this:


    

    

    

    

    

    



    

        

            

        

     


Every element in the XSLT namespace has a type that is derived ultimately from
generic-element-type
, and most of them are also derived from
versioned-element-type
. If we want to use a sequence type descriptor (perhaps to declare a variable or a function argument in XSLT) that accepts any element in the XSLT namespace that is valid against this schema, we could declare this as:


If we wanted to exclude those elements that don't allow a
version
attribute (there is only one,

, which in fact does allow a
version
attribute, but defines it differently), then we could write the sequence type descriptor as:


The schema goes on to provide two abstract element declarations, like this:



These are declared as abstract because you can't actually include an element in a stylesheet whose name is

or

. The reason these two element declarations exist is so that they can act as the heads of substitution groups. This greatly simplifies the definition of other types. For example, there are many places in XSLT where you can use a construct called a
sequence constructor
. A sequence constructor is a sequence of elements in the stylesheet that may include variable definitions, instructions, and literal result elements, and its format is defined in the schema like this:


    

        

        

        

    


Elements that allow a sequence constructor as their content, such as

and

, make use of a complex type definition that refers to this structure:


   

     

       

                 minOccurs=“0” maxOccurs=“unbounded”/>

       

     


The abstract element

was introduced for convenience in defining the schema, but it is equally convenient for describing types in XPath, because we can now write:

schema-element(xsl:instruction)

to match any element that is an XSLT instruction: that is, an element that is in the substitution group of

. An example of such an element is

, which as we have already seen is defined like this:


  

     

       

          

            

          

       

     

  


The schema for XSLT 2.0 stylesheets does not include any global attribute declarations, so you will never see a sequence type descriptor of the form
schema-attribute(xsl:xxxx)
. This is fairly typical: attributes are most commonly declared either as part of the element declaration to which they belong, or in constructs such as
xs:attributeGroup
. For example, the set of
xsl:
prefixed attributes that can appear on literal result elements is defined in the schema for XSLT 2.0 in an attribute group:


 

                      type=“xsl:prefixes”/>

 

                      type=“xsl:prefixes”/>

 

                      type=“xs:anyURI”/> 

 

                      type=“xsl:QNames” default=“”/>

 

                      type=“xs:decimal”/>

 

                      type=“xsl:QName”/>

 

                      type=“xsl:validation-type”/>


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

Other books

Dragonfly by Erica Hayes
Uncertainty by Abigail Boyd
Penthouse by Penthouse International
Red Man Down by Elizabeth Gunn
Beast by Brie Spangler
New America 02 - Resistance by Richard Stephenson
Star Rider by Bonnie Bryant
Her Alien Savior by Elle Thorne
Truth or Date by Susan Hatler