xsl-list
[Top] [All Lists]

RE: [xsl] Request help in understanding: node instance of schema-element(node)

2008-01-27 14:56:16
So, as I understand it, by adding the -val option SAXON 
validates the XML input document against the XML Schema 
specified by the stylesheet:

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


It will also use any schema documents referenced in xsi:schemaLocation if
required.
 
If validation succeeds, then the stylesheet can be certain 
that the <test> element in the input document conforms to the 
test element declaration in the XML Schema.

Correct.

And the stylesheet can check whether validation occurred and 
succeeded by using this if-test:

   if (//test instance of schema-element(test)) then ...

Correct?

Yes. 

Thus, if the processor does not abort and the if-test fails it means:

-- The input XML document was not validated against the XML Schema.

There is no other reason for the if-test failing.

Correct?

Well, there are various other things that could go wrong, like there being
no test element, or there being more than one, but you're on the right
lines. 

The if-test is not requesting the processor perform run-time 
validation of the <test> element against the XML Schema.

Correct?

Yes.

Is this the proper way to check <test> before operating on it?

   if (//test instance of schema-element(test)) then
       //test * 2
   else
       if (//test castable as xs:integer) then
           //test * 2
       else
           'Error'


My preference is to use template rules. Or sometimes I use global variable
declarations:

<xsl:variable name="test-element" select="/test" as="schema-element(test)"/>

which acts as an assertion, causing the stylesheet to fail if not true
(provided $test-element is actually referenced, of course).

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--