[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Seek a simple XPath 2.0 expression to return union

Subject: Re: Seek a simple XPath 2.0 expression to return union xs: simpleType containing xs:string
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 4 Dec 2015 15:12:30 -0000
Re:  Seek a simple XPath 2.0 expression to return union
Correction:

declare function transitive-members-of-union-type($t) {
     let $m := members-of-union-type($t)
     return $m, $m ! transitive-members-of-union-type(.)
};

MK

> On 4 Dec 2015, at 15:07, Michael Kay mike@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> You also need to consider a union type U that has a member type V which is
itself a union type with xs:string as a member - that is, you need to consider
the transitive membership of the union, not just its direct membership.
>
> To do this kind of thing, using XPath directly against the source schema is
simply not a suitable strategy. You should be running queries against the
schema component model.
>
> The following query, which uses Saxon extension functions to access the
schema component model, may be helpful:
>
> declare function all-union-types() {
> 	saxon:schema("type definition")[.("variety") = "union"]
> };
>
> declare function members-of-union-type($t) {
>       $t("member type definitions")
> };
>
> declare function transitive-members-of-union-type($t) {
>      let $m := members-of-union-type($t)
>      return $t, $t ! transitive-members-of-union-type(.)
> };
>
> declare function union-type-has-transitive-member-type($t, $n as xs:QName)
{
>    exists ( transitive-members-of-union-type($t) [ .("name") =
local-name-from-QName($n) and .("target namespace") =
namespace-uri-from-QName($n) ]
> };
>
> all-union-types()[ union-type-has-transitive-member-type(.,
xs:QName('xs:string')) ] ! xs:QName( .("target namespace"), .("name") )
>
> (I've made this output the name of each union type, but it's not clear what
you would want to output when the union type is anonymous).
>
>
> Michael Kay
> Saxonica
>
>
>> On 4 Dec 2015, at 13:15, Costello, Roger L. costello@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>> Hi Folks,
>>
>> I seek an XPath 2.0 expression that returns all XML Schema simpleTypes
containing a union with memberTypes containing the XML Schema string type.
(Phew! Did you catch all that?)
>>
>> So, the XPath should return the union simpleType in this schema:
>>
>>
-----------------------------------------------------------------------------
-----
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>>
>>   <xs:simpleType name="test">
>>       <xs:union memberTypes="xs:int xs:string" />
>>   </xs:simpleType>
>>
>> </xs:schema>
>>
-----------------------------------------------------------------------------
-----
>>
>> The XPath should not return the union simpleType in this schema:
>>
>>
-----------------------------------------------------------------------------
-----
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>>
>>   <xs:simpleType name="test">
>>       <xs:union memberTypes="xs:int string"/>
>>   </xs:simpleType>
>>
>>  <xs:simpleType name="string">
>>      <xs:restriction base="xs:string" />
>>  </xs:simpleType>
>>
>> </xs:schema>
>>
-----------------------------------------------------------------------------
-----
>>
>> I created a horrendously complex XPath 2.0 expression. I think it works
(it's so complex, I'm not sure). Is there a simpler XPath 2.0 expression to
solve this problem?
>>
>> Here's the ugly XPath 2.0 expression that I created:
>>
>> //xs:simpleType[xs:union[@memberTypes]
>>      [exists(index-of(for $here in ., $i in tokenize(@memberTypes, '\s+')
return
>>       namespace-uri-from-QName(resolve-QName($i, $here)) eq
>>          'http://www.w3.org/2001/XMLSchema' and
>>      local-name-from-QName(resolve-QName($i, $here)) eq 'string',
true()))]]
>>
>> /Roger

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.