[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: 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] |
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|