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()='uniqueObject']"/>
      <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 12:12:56 UTC