June 2008
Intermediate to advanced
986 pages
27h 8m
English
To use an XML Schema without <xsl:import-schema>, we have to tie
the XML, the schema, and the stylesheet together. We’ll start by doing
this without namespaces, beginning with the xsi:noNamespaceSchemaLocation attribute in
our XML document:
<?xml version="1.0"?> <!-- parts-list-schema-no-ns.xml --> <parts-list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="parts-list-no-ns.xsd"> <component component-id="C28392-33-TT"> <name>Turnip Twaddler</name> <partref refid="P81952-26-PK"/> <partref refid="P86679-52-SP"/> ...
The schema doesn’t specify a default namespace:
<?xml version="1.0" encoding="UTF-8"?>
<!-- parts-list-no-ns.xsd -->
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="parts-list">
<xs:complexType>
<xs:sequence>
<xs:element ref="component" minOccurs="1" maxOccurs="unbounded"/>
...The only prefix we used here is the one for XML Schema itself. The XML file and the schema are now in sync and namespace-free, so our stylesheet is straightforward:
<?xml version="1.0"?> <!-- id-schema-no-ns.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> ... <xsl:for-each select="/parts-list/part"> <xsl:text>
 </xsl:text> <xsl:value-of select="name"/> <xsl:text> (part #</xsl:text> <xsl:value-of select="@part-id"/> <xsl:text>) is used in these products:
 </xsl:text> <xsl:for-each select="/parts-list/component [partref/@refid=current()/@part-id]" ...
Read now
Unlock full access