This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Automatic copying of text between chapters


On Wed, Apr 03, 2002 at 10:29:11PM +0200, Jirka Kosek wrote:
> dbook@centrum.cz wrote:
> 
> > do you now some docbook's construction, which provides automatic
> > copying of text from one chapter to other?
> 
> You can use text entities or XInclude. 
>  
> > Specially, i make in docbook course of c-language. I need to
> > place exercises for students into end of every chapter and
> > solutions with exercises again into appendix. Because exercises
> > and solutions are large and will be often updated, i want to
> > update it only in appendix. And into end of chapters i want only
> > copy text of exercise from appendix and put there link to
> > solution. Is it possibly?
> 
> You can store each excercise in a separate external text entity and
> include it in two places -- in appendix and in a regular chapter.

If your processor can handle XInclude, then you
can avoid the problem of duplicate IDs for a content module
that is included more than once in a document.

Here is a short example:

1.  Create a modular section file "module.xml" that looks like this:

<?xml version="1.0"?>
<!DOCTYPE section SYSTEM "docbook.dtd">
<section id="original-id">
 <para>
 blah blah
 </para>
</section>

2.  Set up your book document with two slightly different
xinclude elements:

<book>
<chapter>
  blah blah
  <xi:include href="module.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> 
  more blah
</chapter>
<appendix>
  blah blah
  <section id="appendix-id">
    <xi:include href="module.xml#xpointer(/section/*)" xmlns:xi="http://www.w3.org/2001/XInclude"/> 
  </section>
  more blah
</appendix>
</book>

When you process the book file with 

  xsltproc --xinclude docbook.xsl book.xml

you will get two copies in the output and no id conflict.

The first xinclude pulls in the entire <section id="original-id">
element, including its id.  The second xinclude pulls in
only the children of that section element, so the id is not
included.  Instead, the children are pulled into a new
section element with new id.  Now your xrefs can point to
either instance of your copied content, with
linkend="original-id" for the chapter copy, or
linkend="appendix-id" for the appendix version.

Of course, any other id attributes further down within the
modular content will still be duplicated when the two
copies are pulled in.  You won't find out
unless there is a linkend pointing to such an id, and then
it will be reported as a duplicate.  It would be best to avoid
including such additional ids in your modules.

This all depends on using an xslt processor that is capable
of handling xincludes with xpointer syntax, which xsltproc
does.
-- 

Bob Stayton                                 400 Encinal Street
Publications Architect                      Santa Cruz, CA  95060
Technical Publications                      voice: (831) 427-7796
Caldera International, Inc.                 fax:   (831) 429-1887
                                            email: bobs@caldera.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]