RE: XPath + namespace prefixes in key/keyref

Hi Saul,

>       <xs:selector xpath="gr:groupList/*//gr:group"
>                    xmlns:gr="http://me.com/groupns" />
>       <xs:field xpath="@id"/>

As Henry said, your second approach is the right one as far as namespace
prefixes go.  There are a couple other problems, though:

1. You have "@id" for the field, but it will be looking for the id attribute
on the group element, when in your instance it is on the object element.
So, you need to add a step to your xpath, making it
"gr:groupList/gr:group/doc:object". I prefixed "object" with "doc" because
it is in the
http://me.com/documentns default namespace (which you'll have to map to the
prefix "doc").

2. You use "/*//" in the middle of your xpath The XML Schema XPath subset
does not allow the double slash, unless it is at the beginning of the xpath
and preceded by a period (e.g. xpath=".//gr:group").  But, according to your
instance, eliminating this step would not change the meaning of the
selector.

Hope that helps,

Priscilla

-----------------------------------------------------------
Priscilla Walmsley                   priscilla@walmsley.com
Vitria Technology                     http://www.vitria.com
Author, Definitive XML Schema    (Prentice Hall, Dec. 2001)
-----------------------------------------------------------

> -----Original Message-----
> From: xmlschema-dev-request@w3.org
> [mailto:xmlschema-dev-request@w3.org]On Behalf Of Saul Farber
> Sent: Monday, November 05, 2001 12:16 PM
> To: xmlschema-dev@w3c.org
> Subject: XPath + namespace prefixes in key/keyref
>
>
> Hello all,
>
> I'm running into the following problem while creating a
> schema that uses
> key and keyref elements.
>
> take the following xml document (extraneous detail removed):
>
> <?xml version="1.0"?>
> <document xmlns="http://me.com/documentns">
>
>   <!-- define some unique objects -->
>   <unq:uniqueObjectList xmlns:unq="http://me.com/listns">
>     <unq:uniqueObject id="1">
>       <unq:info>This object is a blue ball</unq:info>
>     </unq:uniqueObject>
>     <unq:uniqueObject id="2">
>       <unq:info>This object is a blue iMac</unq:info>
>     </unq:uniqueObject>
>   </unq:uniqueObjectList>
>
>   <!-- now reference them in some groups -->
>   <gr:groupList xmlns:gr="http://me.com/groupns">
>     <gr:group name="bluethings">
>       <gr:desc>Objects that are blue</gr:desc>
>       <object id="1"/>
>       <object id="2"/>
>     </gr:group>
>     <gr:group name="electricthings">
>       <gr:desc>Objects that are electric</gr:desc>
>       <object id="2"/>
>     </gr:group>
>     <gr:group name="roundthings">
>       <gr:desc>Objects that are round</gr:desc>
>       <object id="1"/>
>     </gr:group>
>   </gr:groupList>
>
> </document>
>
>
> Whew!  So here's the problem:
> As is probably obvious from the example, I'd like to keyref the
>
>         <object id="x" />
>
> tags into the
>
>     <unq:uniqueObject id="1">
>       <unq:info>This object is a blue ball</unq:info>
>     </unq:uniqueObject>
>
> blocks, via the "id" attribute in each case.
>
> However, I'm unable to assume anything about the prefix abbreviation
> that will be associated with the namespaces "http://me.com/listns" and
> "http://me.com/groupns"...because this xml fragment is actually a
> message passed to me (therefore I don't get to assume that 'gr' is the
> prefix associated with "http://me.com/groupns").  So I face
> the question
> of what to put into the xpath attribute of the key and keyref
> schema-elements (which must obviously be children of the <document>
> schema-description). My attempts were:
>
> 1)  Use the local-name() function of Xpath.  like this:
>
>   <xs:element name="document">
>     <xs:complexType>
>     ...
>     <!-- insert schema-description of the children of <document> -->
>     </xs:complexType>
>
>     <xs:key name="layerDefinitionKey">       <xs:selector
> xpath="*[local-name()='uniqueObjectList']/*[local-name()='uniq
> ueObject']"/>
>       <xs:field xpath="@id"/>
>     </xs:key>
>
>     <xs:keyref name="thisStringDoesntMatter"
>                refer="tns:layerDefinitionKey">
>       <xs:selector
> xpath="*[local-name()='groupList']/*//*[local-name()='group']"/>
>       <xs:field xpath="@id"/>
>     </xs:keyref>
>
>
> However, Xerces barfs on the '[' character in the xpath
> attribute...and
> besides, this isn't really a good solution, I don't think.
>
> 2)  declare the namespace-prefix that I want right next to the xpath
> element
>
>   <xs:element name="document">
>     <xs:complexType>
>     ...
>     <!-- insert schema-description of the children of <document> -->
>     </xs:complexType>
>
>     <xs:key name="layerDefinitionKey">       <xs:selector
> xpath="list:uniqueObjectList/list:uniqueObject"
>                     xmlns:list="http://me.com/listns" />
>       <xs:field xpath="@id"/>
>     </xs:key>
>
>     <xs:keyref name="thisStringDoesntMatter"
>                refer="tns:layerDefinitionKey">
>       <xs:selector xpath="gr:groupList/*//gr:group"
>                    xmlns:gr="http://me.com/groupns" />
>       <xs:field xpath="@id"/>
>     </xs:keyref>
>
> However I've had no luck this way, either!
>
> It seems to me that this is simply an instance of a larger
> problem...how
> to deal with potentially unknown namespace prefixes.  In standard xslt
> transformations I can usually get away with the [local-name() = 'foo']
> trick...but not in this case.
>
> Is there a real solution to this, or is this a fundamental
> problem with
> XML-Schema?
>
> thanks!
>
> saul
>
> --
> Syncline, Inc.
> 373 Washington St.
> Boston, MA  02108
>
> 617-986-1000 (x248)
>
> www.syncline.com -- Informing the Enterprise
> www.mapciti.com -- It's Your Town on the Web
>

Received on Monday, 5 November 2001 13:15:15 UTC