[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Is an XPath processor responsible for catching mi

Subject: Re: Is an XPath processor responsible for catching misspelled tag names when there is an associated Schema?
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Thu, 21 Feb 2008 16:33:56 +0000
Re:  Is an XPath processor responsible for catching  mi
On 21/02/2008, Michael Kay <mike@xxxxxxxxxxxx> wrote:
>  Saxon will give you a compile time warning for this situation. However, if
>  there is no static type information available, then it can't do this. To get
>  maximum benefit from schema-aware processing, you should declare the types
>  of your variables and function parameters (and especially, the type of the
>  principal input).

Here's a little example to demonstrate that:

<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

    <xsl:import-schema>
        <xs:schema>
            <xs:element name="shapes" type="shapes"/>
            <xs:element name="shape" type="xs:string"/>

            <xs:complexType name="shapes">
                <xs:sequence>
                    <xs:element ref="shape"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </xsl:import-schema>

    <xsl:variable name="input" as="schema-element(shapes)">
    	<shapes xsl:type="shapes">
    		<shape>Hello</shape>
    	</shapes>
    </xsl:variable>

    <xsl:template match="/" name="main">
        <xsl:value-of select="$input/shap"/>
    </xsl:template>

</xsl:stylesheet>

The xsl:import-schema element defines the schema for the input, and
the $input variable contains some XML that gets typed by that schema
using the xsl:type attribute.

In the main template the value-of select is deliberately misspelt,
which results in the following warning:

"The complex type shapes does not allow a child element named shap"

...which is great :)


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.