OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] XInclude & Document Function.

[ Lists Home | Date Index | Thread Index ]

Hi Arun,

> I have a Main.xml which includes Books.xml
>
> Main.xml
> <Response>
>      <node1 href='books.xml'></node>
> </Response>
>
> Books.xml
> <mynode>
> <a>Hello All</a>
> </mynode>
>
> Main.xsl
> <xsl:value-of select="document(Response/node1/@href)/mynode"/>
>
> document() function works fine.
>
> Can anyone clarify
> 1. What is the difference between including an XML Using XINCLUDE
> namespace to that of the above mentioned way.

Well, first there's a difference in terms of what you get, or how you
describe what you want to get. From the looks of it, what you have
above would result in:

  <Response>Hello All</Response>

The rough equivalent of what you've done above, using XInclude is:

  <Response xmlns:xi="http://www.w3.org/2001/XInclude";>
    <xi:include href='books.xml' />
  </Response>

The result of this would be:

  <Response>
    <mynode xml:base="http://www.opussoft.com/Books.xml";>
      <a>Hello all</a>
    </mynode>
  </Response>

Where 'http://www.opussoft.com/Books.xml' is an absolute URL for the
books.xml document that you're using.

There are two things to note here - firstly that the entire XML
structure of the referenced document is included into the result when
you use XInclude; secondly that the XInclude processor should add an
xml:base attribute to the document element, such that any relative
URLs within the referenced document are interpreted correctly.

To put it another way, with XInclude you get something closer to:

  <xsl:copy-of select="document(node1/@href)" />

rather than the xsl:value-of that you were using (although still you'd
need to add the xml:base attribute as well).

More generally, it's hard to tell what the differences are from this
one example. XInclude can be used to reference just parts of an XML
document in order to include them, and can be used to reference text
documents to include them. It can also contain xi:fallback elements to
provide alternatives if the referenced document isn't available for
some reason. Your element might or might not also do those things - I
can't tell from a single example - certainly your element doesn't have
the functionality of xi:include if the only way you use it is with the
XSLT code that you've shown.

At a higher level, XInclude is on its way to being a standard
(currently it's a Candidate Recommendation) whereas what you're using
is specific to your application. Which leads on to your second
question...

> 2. When & Why one should use XINCLUDE.

I think that you're asking when you should use XInclude as opposed to
an element with similar functionality in your own namespace.

Either way has advantages and disadvantages. Using the XInclude
standard means that people can read your document and know what you
intend to happen, and it means that you can use XInclude processors to
do the including rather than rolling your own processor. On the other
hand, you can define your own element to do whatever you want it to
do, so you have absolute control over what your element means.

Personally, I'd use XInclude in my XML, even if I still rolled my own
stylesheet to interpret the xi:include elements rather than using a
third-party XInclude implementation.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS