xsl-list
[Top] [All Lists]

[xsl] matching elements by name and type to detect invalid xpaths

2008-10-06 13:09:12
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/

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

<Prev in Thread] Current Thread [Next in Thread>