[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Validating source documents, with schema aware XSLT


Subject: [xsl] Validating source documents, with schema aware XSLT
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sat, 5 Aug 2006 21:10:47 +0530

I am trying to run a schema-aware stylesheet using Saxon-SA 8.7.1J.

The example I am trying is mentioned in Michael Kay's book "XSLT 2.0
Programmer's Reference, 3rd Edition" 's chapter 4 Stylesheets and
Schemas, Validating the Source Document.

The stylesheet I am trying is:

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

<xsl:import-schema schema-location="books.xsd" />

<xsl:template match="/">
 <xsl:if test="not(* instance of schema-element(BOOKLIST))">
   <xsl:message terminate="yes">
      Source document is not a validated book list
   </xsl:message>
 </xsl:if>
 <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>

The source XML is books.xml, and Schema is books.xsd found in the
folder samples\data of Saxon distribution.

The example works fine with the following command line:

java com.saxonica.Transform -val books.xml books.xsl

The source document gets validated, and I get the proper output.

However, I am curious what is happening in the following cases:

1) I give the command line as, java com.saxonica.Transform books.xml
books.xsl (i.e. no -val option)

The following message comes from the stylesheet:

Source document is not a validated book list

Processing terminated by xsl:message at line 7 in books.xsl

2) I give the command line as, java com.saxonica.Transform -val
books.xml books.xsl

but I remove the line <xsl:import-schema schema-location="books.xsd"
/> from the stylesheet,

I get message,

XPST0003: XPath syntax error at char 42 on line 4 in {...e of schema-element(B
OOKLIS...}:
No schema has been imported for namespace ''

According to my testing, it seems that to validate source document,
-val option is a must, and also xsl:import-schema is a must to include
in the stylesheet. i.e. both these conditions must be fulfilled for
the source document to get validated by the schema, and is usable by
the stylesheet.

But the Saxon documentation confuses me. It says..

"To run a schema-aware transformation from the command line, use the
com.saxonica.Transform command instead of the usual
net.sf.saxon.Transform. This has an additional option -val to request
strict validation of the source document.

The schemas to be used to validate these source documents can be
specified either by using the xsl:import-schema declaration in the
stylesheet, or using xsi:schemaLocation (or
xsi:noNamespaceSchemaLocation) attributes within the source documents
themselves."

The Saxon documentation clearly seems to say, in the absence of
xsl:import-schema declaration, the schema will be picked from the
xsi:schemaLocation (or xsi:noNamespaceSchemaLocation) attributes
within the source document.

In the XML file I tried, its written (i.e. I have a
xsi:noNamespaceSchemaLocation attribute):
<BOOKLIST xsi:noNamespaceSchemaLocation="books.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <!-- contents -->
</BookLIST>

So it seems, the output I am getting in option 2) above and Saxon
documentation contradict..

Could someone please clarify my doubts?

--
Regards,
Mukul Gandhi

http://gandhimukul.tripod.com


Current Thread
Keywords