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

matching elements by name and type to detect invalid

Subject: matching elements by name and type to detect invalid xpaths
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Mon, 6 Oct 2008 18:08:41 +0100
 matching elements by name and type to detect invalid
I know I moaned about input validation the other day but I hadn't come
across this:

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

    <xsl:import-schema>
        <xs:schema>
            <xs:complexType name="root">
                <xs:sequence>
                    <xs:element name="child" />
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </xsl:import-schema>

    <xsl:template match="element(root, root)">
            <xsl:value-of select="wrong" />
    </xsl:template>

</xsl:stylesheet>

Compile that with a schema-aware processor (Saxon SA in this case) and
you are told:

"The complex type root does not allow a child element named wrong;"

You don't even have to validate any input, because the match pattern
contains the type it knows that "wrong" is not a child of <root>...
fantastic :)

I think this means you can enjoy the benefits of the paths in your
XSLT being checked against the schema _without_ being forced to
validate the input each time... which is a huge benefit.

(sorry if you were well aware of this already)


-- 
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.