>UntypedAtomic and YearMonthDuration Casting Question

>While working on the PsychoPath XPath 2.0 processor in the eclipse WTP project, I ran across the following situation. According the the W3C XPath 2.0 test suite test case CastableAs030 the following test should fail:


xs:untypedAtomic("-P1Y1M1DT1H1M1.123S") castable as xs:yearMonthDuration

The result should be false, however, we are returning true. As far as my understanding of the specification, the xs:untypedAtomic value should be treated as a string value, and when casting to xs:yearMonthDuration only the form of “-P1Y1M1” is processed ignoring the rest. It also appears that this is a validation duration describing:
a negative 1 year, 1 month, 1 day, 1 hour, 1 minute, and 1.123 seconds

At least that is my interpretation of section 17.1.4 of Casting from primitive types to primitive types. Am I missing something or is this a known bug in the W3C Test Suite?

Advertisements
This entry was posted in xml, xpath. Bookmark the permalink.

3 Responses to >UntypedAtomic and YearMonthDuration Casting Question

  1. >It looks to me as if the test suite is correct. I think you may be assuming implicitly that the untypedAtomic value is cast first to xs:duration, and then to xs:yearMonthDuration. But that's not what happens here.Section 17.1.4 "Casting to duration types" describes the relevant case with the words If ST is xs:untypedAtomic or xs:string, see 17.1.1 Casting from xs:string and xs:untypedAtomic.What seems to me to be the relevant part of section 17.1.1 is the first sentence: When the supplied value is an instance of xs:string or an instance of xs:untypedAtomic, it is treated as being a string value and mapped to a typed value of the target type as defined in [XML Schema Part 2: Datatypes Second Edition]. But the string you supply does not map to a yearMonthDuration value: the lexical space of yearMonthDuration does not include any strings which have day, hour, minute, or seconds fields. The description in 10.3.1 of Functions and Operators says: [Definition] xs:yearMonthDuration is derived from xs:duration by restricting its lexical representation to contain only the year and month components. This is operationalized by the declaration of yearMonthDuration in the XDM spec: it supplies a pattern facet with the value [^DT]*, which has the effect of ruling out the string form of your untypedAtomic value.

  2. David Carver says:

    >@C.M.Sperberg-McQueen:Okay so roughly translated:1. xs:string or xs:untypedAtomic and has duration values with either D,T,H,M,S then it can't be cast.2. xs:string or xs:untypedAtomic and has only YM, Y, or M duration it can be cast.3. if xs:duartion it can be cast using the ym values if they exist.4. Anything else is uncastable.

  3. David Carver says:

    >I was able to get this to work, Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s