andrewjwelch.com
schema-aware.com
schema-aware XSLT and XQuery examples
SAXONICA

Handling basic and validated input in the same stylesheet

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

    
<xsl:import-schema schema-location="the-schema.xsd" />
    
    
<xsl:template match="document-node(schema-element(the-root-element))">
        normal case
    
</xsl:template>
    
    
<xsl:template match="/">
        error case
    
</xsl:template>
    
</xsl:stylesheet>
Both templates match the document node - the first will be matched when the input has been validated and the root element is correctly typed, the second will match non-validated input.