xsl-list
[Top] [All Lists]

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

2008-01-27 00:32:35
Hi Mike,
   Though I don't doubt very much the reasons behind the current
Schema awareness design in the XSLT 2.0 spec.

But I have a personal curiosity, related to Roger's question in this thread.

I would have preffered a syntax

     <xsl:value-of select="if (//test instance of
schema-element(test)) then
                             //test * 2
                             else 'Error'"/>

Without doing, <xsl:import-schema schema-location="test.xsd"/> in the
2.0 stylesheet.

(I think, having the declaration, <xsl:import-schema
schema-location="test.xsd"/> in stylesheet provides static
availability of type information, without having dynamic introspection
from PSVI - which I probably like).

The XSLT 2.0 processor should be able to get type information from
Schema, after the validation event (either by -val / -val:strict
options, or from the xsi:schemaLocation attribute in the instance
document). Does Saxon-SA support xsi:schemaLocation method as well
(and I don't do -val / -val:strict) ? If Saxon doesn't support
xsi:schemaLocation method, my curiosity is, why not?

On Jan 27, 2008 4:25 AM, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:

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/



-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
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>
--~--