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

XLink, XInclude, and xml:base

  • To: <xml-dev@l...>
  • Subject: XLink, XInclude, and xml:base
  • From: "Magnus Henriksson (MO/EAB)" <magnus.henriksson@e...>
  • Date: Tue, 27 Sep 2005 16:46:52 +0200
  • Thread-index: AcXDckyQcEfD0gh6S6ydakbHBmydbw==
  • Thread-topic: XLink, XInclude, and xml:base

customer.gif
Hi all,

I need some help understanding the interaction between XLinks, XInclude, and xml:base.


Assume I have the following document.xml:

<?xml version="1.0"?>
<document xml:base="http://example.com"
          xmlns:xi="http://www.w3.org/2001/XInclude">
  <paragraph>How to handle customers:</paragraph>
  <xi:include href="common/policy.xml"/>
</document>


policy.xml looks like this:

<?xml version="1.0"?>
<list xmlns:xlink="http://www.w3.org/1999/xlink">
  <item xml:id="item1">The customer is always right.</item>
  <item>When the customer is wrong, see <link xlink:type="simple"
                                              xlink:href="#item1"/>.</item>
  <graphic xlink:type="simple"
           xlink:actuate="onLoad"
           xlink:show="embed"
           xlink:href="../images/happy-customer.gif"/>
</list>


If run document.xml through an XInclude processor, I get the following result:

<?xml version="1.0"?>
<document xmlbase="http://example.com"
          xmlns:xi="http://www.w3.org/2001/XInclude" >
  <paragraph>How to handle customers:</paragraph>
  <list xmlns:xlink="http://www.w3.org/1999/xlink"
        xml:base="common/policy.xml">
    <item xml:id="item1">The customer is always right.</item>
    <item>When the customer is wrong, see <link xlink:type="simple"
                                                xlink:href="#item1"/>.</item>
    <graphic xlink:type="simple"
             xlink:actuate="onLoad"
             xlink:show="embed"
             xlink:href="../images/happy-customer.gif"/>
  </list>
</document>


My problem is that the link points to http://example.com/common/policy.xml#item1, but I really want it to point to #item1 in the XIncluded result. The graphic points to http://example.com/images/happy-customer.gif which is what I want.

In this simple example, it would be quite easy to resolve the full URL of the graphic and then remove all xml:base attributes (e.g. using a transform, SAX, ...). Using this method, I can transform URLs in different elements to something that makes sense to me. So far, so good? What I cannot understand, is how you do something like this when using more complex inclusions and XLinks.


For example, assume I have the following document2.xml:

<?xml version="1.0"?>
<document xml:base="http://example.com"
          xmlns:xi="http://www.w3.org/2001/XInclude">
  <paragraph>How to handle customers:</paragraph>
  <list>
    <xi:include href="common/policy2.xml"
                xpointer="xpointer(list/*)"/>
  </list>
</document>


policy2.xml looks like this:

<?xml version="1.0"?>
<list xmlns:xlink="http://www.w3.org/1999/xlink">
  <item xml:id="item1">The customer is always right.</item>
  <item>When the customer is wrong, see <link xlink:type="simple"
                                              xlink:href="#xpointer(list/item[1])"/>.</item>
  <graphic xlink:type="simple"
           xlink:actuate="onLoad"
           xlink:show="embed"
           xlink:href="../images/happy-customer.gif"/>
</list>


If run document2.xml through an XInclude processor, I get the following result:

<?xml version="1.0"?>
<document xml:base="http://example.com"
          xmlns:xi="http://www.w3.org/2001/XInclude">
  <paragraph>How to handle customers:</paragraph>
  <list>
    <item xml:id="item1"
          xml:base="common/policy2.xml">The customer is always right.</item>
    <item xmlns:xlink="http://www.w3.org/1999/xlink"
          xml:base="common/policy2.xml">When the customer is wrong, see <link xlink:type="simple"
                                                                              xlink:href="#xpointer(list/item[1])"/>.</item>
    <graphic xmlns:xlink="http://www.w3.org/1999/xlink"
             xlink:type="simple" xlink:actuate="onLoad"
             xlink:show="embed" xlink:href="../images/happy-customer.gif"
             xml:base="common/policy2.xml"/>
  </list>
</document>


Now what? If I simply remove the xml:base attributes, the XPointer in <link> will not point to anything. It would need to be changed into, for example, xpointer(document/list/item[1]). This whole thing quickly gets very complex when you start adding sophisticated XIncludes and XLinks, and XLinks between documents or parts of documents that sometimes are included, sometimes not.

OK, what I seem to be looking for: Is there a way to determine whether an XLink points to something that is part of the current XIncluded result? And if I'm so lucky, is there a way to update those XLinks to point the corresponding thing in the XIncluded result? Or am i just nuts?



// Magnus

-- 
Magnus Henriksson        Ericsson AB
+46 31 747 6933          Transmission & Transport


This communication is confidential and intended solely for the addressee(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you believe this message has been sent to you in error, please notify the sender by replying to this transmission and delete the message without disclosing it. Thank you.

E-mail including attachments is susceptible to data corruption, interruption, unauthorized amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, amendment, tampering or viruses or any consequences thereof.

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.