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

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


Subject: RE: [xsl] Request help in understanding: node instance of schema-element(node)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 26 Jan 2008 22:55:56 -0000

> Apparently I am not correctly understanding this XPath statement:
> 
>     if (//test instance of schema-element(test)) then  
>         //test * 2 
>     else 'Error'
> 
> My understanding of the XPath is this: "If the <test> element 
> in the input document conforms to the declaration of test in 
> the XML Schema then multiply its value by 2, otherwise output Error."

See my XPath 2.0 Programmer's Reference page 287 regarding "instance of": 

"It's important to remember, whether you are testing atomic values or nodes,
that the "instance of" operator is testing whether the value has a label
that identifies it as a member of the specified type. It isn't testing
whether the value would be a valid member of that type if the label were
changed."

It goes on:

"the fact that validation against this type would succeed is not enough; the
validation must actually have been done, so that the required type
annotation is present on the node."

This is not that dissimilar from other languages: in Java, ("2008-01-25"
instanceof Date) returns false.
> 
> What am I doing wrong?
> 
> I am using the schema-aware version of SAXON, version 
> 8.9.0.4j.  Below is the stylesheet, XML Schema, and XML document.
> 
You haven't shown the bit that you did wrong, which was almost certainly to
run the stylesheet against an unvalidated input document. With Saxon, you
request validation by using an option on the command line (-val for 8.9.0.4,
-val:strict for 9.0.0.n) (or of course via the Java API). With Altova, you
request validation by including an xsi:schemaLocation attribute in the
instance document.

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


Current Thread
Keywords