Subject: [xsl] Validating source documents, with schema aware XSLT From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sat, 5 Aug 2006 21:10:47 +0530 |
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.
<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>
The source XML is books.xml, and Schema is books.xsd found in the folder samples\data of Saxon distribution.
1) I give the command line as, java com.saxonica.Transform books.xml books.xsl (i.e. no -val option)
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,
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.
"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..
-- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: RE: [xsl] Selecting the first n, Wendell Piez | Thread | [xsl] Re: Validating source documen, Mukul Gandhi |
Re: [xsl] Selecting the first node , G. Ken Holman | Date | [xsl] Re: Validating source documen, Mukul Gandhi |
Month |