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

The "hello world" schema aware transform

Validating the result using xsl:result-document with the xsl:validation attribute.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="2.0">
    
    
<xsl:import-schema namespace="http://www.w3.org/1999/xhtml" schema-location="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" />
    
    
<xsl:template match="/">
        
<xsl:result-document xsl:validation="strict">
            
<html>
                
<head>
                    
<title>Schema Aware XSLT example</title>
                
</head>
                
<body>
                    
<div>Hello World</div>
                
</body>
            
</html>
        
</xsl:result-document>
    
</xsl:template>   
    
</xsl:stylesheet>
Validation is invoked by the xsl:validation attribute on the <xsl:result-document> instruction. The allowed values are strict, lax, preserve or strip. In this case its "strict" which means the element must be validated and its an error if a definition cannot be found.