import-schema_1-input.xml
<?xml version="1.0"?>
<products>
<product
id="p1" name="Delta" price="800" stock="4" country="Denmark"/>
</products>
import-schema_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:import-schema
schema-location="import-schema_1.xsd"/>
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<products
xsl:validation="strict">
<xsl:copy-of
select="products/product"/>
<product
id="p6" name="Romeo" price="2250" stock="5" country="South Africa"/>
</products>
</xsl:template>
</xsl:stylesheet>
import-schema_1-schema.xsd
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element
name="products">
<xs:complexType>
<xs:sequence>
<xs:element
name="product" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute
name="id" type="xs:ID" use="required"/>
<xs:attribute
name="name" type="xs:string" use="required"/>
<xs:attribute
name="price" type="xs:decimal" use="required"/>
<xs:attribute
name="stock" type="xs:integer" use="required"/>
<xs:attribute
name="country" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
import-schema_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product
id="p1" name="Delta" price="800" stock="4" country="Denmark"/>
<product
id="p6" name="Romeo" price="2250" stock="5" country="South Africa"/>
</products>
xsl:import-schema only works in a schema-aware XSLT processor. It makes input validation, validation of temporary trees and output validation possible. In our example the new product element is validated against the imported schema.
Updated 2009-03-19