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

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] Filtering out sections?


Hi Lars,

Am Sonntag, 27. November 2011, 12:51:41 schrieb Lars Vogel:
> [...]
> <section>
> <title> Debugging</title>
>       <section>
>               <title> Detail1 </title>
>        </section>
>           <section>
>               <title> Detail2 </title>
>        </section>
> </section>
> 
> I want to re-use Detail1 and Detail2 in an larger document of type "book".
> I do this via an x-include.
> 
> <chapter>
>  <title>Developing Java</title>
> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude";
> href="../EclipseDebugging/content/010_content.xml" />
>  </chapter>
> 
> Unfortunately this brings also in the first section of the article which I
> would like to filter out. The desired result would be:
> 
> <chapter>
> <title>Developing Java</title>
>  <section>
>               <title> Detail1 </title>
>        </section>
>           <section>
>               <title> Detail2 </title>
>        </section>
> </chapter>
>  Is that possible via a kind of filtering?

Hmn, reusing fragments of a file is challenging, but not impossible. :) You 
*could* use so called "XPointers" which were specified for such a task.

However, and this is the big disadvantage, XPointers are not fully released as 
a W3C recommendation. Furthermore, only parts of the XPointers specifications 
(plural!) are supported by XML parsers (if at all). The xmllint parser seems 
to support _some_ but not all.

If you are not frightend by XPointers, you could extend your above XIncludes 
with a xpointer attribute (untested!):

  <chapter>
    <title>Developing Java</title>
    <section>
      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude";
        href="../EclipseDebugging/content/010_content.xml"
        xpointer="element(/1/1/node())"/>
    </section>
    <section>
      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude";
        href="../EclipseDebugging/content/010_content.xml"
        xpointer="element(/1/2/node())"/>
    </section>
  </chapter>
 
The above element(...) keyword uses an XPath notation to select the first and 
second section elements and includes only their contents. As you have already 
assumed, it highly depends on your structure of your referenced file. If that 
changes, you will have to adapt your XPointers as well.

If the above notation doesn't work, another solution would be to use an ID 
selection scheme. Insert in your Details 1 and 2 sections unique IDs and 
select them with the xpointer() and id() scheme:

  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude";
        href="../EclipseDebugging/content/010_content.xml"
        xpointer="xpointer(id(sec.detail1)/node())"/>

However, putting IDs in sections and reusing them is always a bit dangerous as 
you can end up with multiple IDs in your documents.

If you would like to know more about this topic, here are some further links:

 http://www.sagehill.net/docbookxsl/DuplicateIDs.html
 http://blog.fischermatthias.net/2011/03/16/xiinclude-auflosen-mit-xmllint/

There are probably more ideas, but I leave that for another mail. :)


-- 
Gruß/Regards
  Thomas Schraitle



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]