XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] XPath 2.0 Best Practice Issue: Graceful Degradation



I still think the "Alternate (Degraded) Behavior" is bad xpath style.

    if (//airplane[@tailnum='C3H1'] instance of schema-element(airplane)) then 
            //airplane[@tailnum='C3H1']/altitude * .3048  
    else 
        if (//airplane[@tailnum='C3H1']/altitude[@unit='feet'] castable as xs:double) then 
            //airplane[@tailnum='C3H1']/altitude * .3048
        else
            'Error'


firstly even if you are doing xpath checks rather than a schema
validation I'd try to keep the two activities as separate as possible
not try to entwine them as here. Otherwise the code just becomes
confusing and you end up thinking that you have checked things that you
have not.

For example the above falls over relatively ungracefully if there are
two airplane[@tailnum='C3H1' elements, and fixing that would quite
easily lead to code that tested one element matched the criterion but
used another element in the calculation (as there is nothing to relate
the two except that you will get a run time error if there are two
elements).

The above will give you either a number or 'Error', so you'd have to
test which you get, so it's really not much different from just using

            //airplane[@tailnum='C3H1']/altitude[@unit='feet'] * .3048
and testing that the result isn't NaN, 

Note that this simpler form also achieves your aim

> provide an alternate course of action for
> environments that do not support schema-validation.

which is not the case for the version you posted as schema-element()
will generate a compile time error in an XSLT engine that doesn't
support schmem awareness.

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS