xsl-list
[Top] [All Lists]

Re: [xsl] Is an XPath processor responsible for catching misspelled tag names when there is an associated Schema?

2008-02-21 09:34:28
On 21/02/2008, Michael Kay <mike(_at_)saxonica(_dot_)com> 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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--