using XML to reference XML; XPointers and keys

Subject: using XML to reference XML; XPointers and keys
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Mon, 15 Nov 1999 11:19:00 -0700
Perhaps someone can help. I have some source data that looks like:

<doc1>
  <MyData id="101">...</MyData>
  <MyData id="102">...</MyData>
  ...
</doc1>

And I reference it in multiple places in another XML tree:

<doc2>
  ...
  <MyDataRef idref="102"/>
  ...
  <MyDataRef idref="102"/>
  ...
  <MyDataRef idref="101"/>
  ...
</doc2>

I process doc2 with an XSLT stylesheet. When I need to access the MyData
that has the same @id as the MyDataRef @idref, I use a key. This is a fine
abstraction since I have something to key on.

But now I also have to use some source data that looks like this, with
nothing consistent to key on:

<doc3>
  <Merchant MerchantID="123">
    <ContactInfo>
      <Name>Joe's Pizza</Name>
      <Address>1111 22nd Ave</Address>
      <City>Cleveburgville</City>
      <State>OH</State>
      <Phone>2165551212</Phone>
    </ContactInfo>
    ...
  </Merchant>
</doc3>

I'd like to be able to reference this data in a similar way. I'd like to be
able to have in doc2 something like:

<MyDataRef elementref="Address"/>

And then use a key to get the appropriate node in doc3. I think this can be
done, but things get tricky when I need to have repeating elements in doc3.
For example, Address can appear in a different context:

<doc3>
  <Merchant MerchantID="123">
     <ContactInfo>
        <Address>1111 22nd Ave</Address>
     </ContactInfo>
     <BillingInfo>
        <Address>2222 11th St</Address>
     </BillingInfo>
  </Merchant>
</doc3>

How can I point to just the Address that's a child of ContactInfo? Defining
<MyDataRef elementref="/doc3/Merchant/ContactInfo/Address"/> is useless
because I can't, without some kind of recursive voodoo that breaks down as
soon as you hit a predicate, use that elementref string to obtain a
node-set.

It seems like XPointer covers this territory, using an element in a custom
namespace to point to particular nodes or locations in a document's data ...
but it would be up to the XSLT engine to implement them, right?

Any other suggestions for a way to abstract the doc3 data?

-Mike


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread