DocBook custom XSL transformations

Discussion in 'XML' started by Szymon Nieradka, May 11, 2006.

  1. Hi,

    I'm trying to make a docbook document template. I would like to make
    my life easier and instead of writing:

    <glosslist>
    <glossentry>
    <glossterm>C</glossterm>
    <glossdef>
    <para>
    A procedural programming language invented by K&amp;R.
    </para>
    </glossdef>
    </glossentry>
    <!-- ... -->
    </glosslist>

    I'd like to write:

    <glosslist>
    <glossEntry term="C">
    A procedural programming language invented by K&amp;R.
    </glossEntry>
    <!-- ... -->
    </glosslist>

    (of course thats only example of use)

    I'm making transormations of DocBook file using my custom XSL
    stylescheet. This XSL stylescheet have got some default include at the
    top (for ex. .../docbook/html/docbook.xsl). Abow I'm putting my addons.
    I was trying to do what I want this way:

    <xsl:template match="glossEntry">
    <!-- (1) -->
    <xsl:value-of select="@term"/> <!-- term -->
    <!-- (2) -->
    <xsl:value-of select="."/> <!-- definition -->
    </xsl:template match="glossEntry">

    At (1) I have to resolve / call <glossentry> and at (2) I have to do the
    same with <glossdef> and <para>. I was trying a lot of combinations of:

    <xsl:call-template name="glossentry"/>

    and

    <xsl:apply-templates select="glossentry"/>

    but without success.

    Of course I could insert HTML tags diresctly (<dl/>) but I'm not only
    interested in HTML, I need also RTF and PDF output.

    Any ideas? Is it possible?

    --
    Szymon Nieradka
    Szymon Nieradka, May 11, 2006
    #1
    1. Advertising

  2. Szymon Nieradka

    Peter Flynn Guest

    Szymon Nieradka wrote:
    > Hi,
    >
    > I'm trying to make a docbook document template. I would like to make
    > my life easier and instead of writing:
    >
    > <glosslist>
    > <glossentry>
    > <glossterm>C</glossterm>
    > <glossdef>
    > <para>
    > A procedural programming language invented by K&amp;R.
    > </para>
    > </glossdef>
    > </glossentry>
    > <!-- ... -->
    > </glosslist>
    >
    > I'd like to write:
    >
    > <glosslist>
    > <glossEntry term="C">
    > A procedural programming language invented by K&amp;R.
    > </glossEntry>
    > <!-- ... -->
    > </glosslist>
    >
    > (of course thats only example of use)


    Why use XSL?
    Just redefine the elements involved: that's why DocBook is modular.

    dbglossmod.dtd
    --------------
    <!ENTITY % docbookdtd SYSTEM "/your/path/to/the/docbookx.dtd">

    <!ENTITY % glosslist.element "IGNORE">
    <!ENTITY % glosslist.attlist "IGNORE">
    <!ENTITY % glossentry.element "IGNORE">
    <!ENTITY % glossentry.attlist "IGNORE">

    %docbookdtd;

    <!ELEMENT glosslist %ho; (glossentry+)>
    <!ELEMENT glossentry %ho; (%para.char.mix;)*>
    <!ATTLIST glossentry term CDATA #REQUIRED>

    test.xml
    --------
    <?xml version="1.0"?>
    <!DOCTYPE article SYSTEM "dbglossmod.dtd">
    <article>
    <glosslist>
    <glossentry term="C">A procedural programming language invented by
    K&amp;R.</glossentry>
    </glosslist>
    </article>

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, May 12, 2006
    #2
    1. Advertising

  3. Peter Flynn wrote:
    > Why use XSL?
    > Just redefine the elements involved: that's why DocBook is modular.
    >
    > dbglossmod.dtd
    > --------------
    > <!ENTITY % docbookdtd SYSTEM "/your/path/to/the/docbookx.dtd">
    >
    > <!ENTITY % glosslist.element "IGNORE">
    > <!ENTITY % glosslist.attlist "IGNORE">
    > <!ENTITY % glossentry.element "IGNORE">
    > <!ENTITY % glossentry.attlist "IGNORE">
    >
    > %docbookdtd;
    >
    > <!ELEMENT glosslist %ho; (glossentry+)>
    > <!ELEMENT glossentry %ho; (%para.char.mix;)*>
    > <!ATTLIST glossentry term CDATA #REQUIRED>
    >
    > test.xml
    > --------
    > <?xml version="1.0"?>
    > <!DOCTYPE article SYSTEM "dbglossmod.dtd">
    > <article>
    > <glosslist>
    > <glossentry term="C">A procedural programming language invented by
    > K&amp;R.</glossentry>
    > </glosslist>
    > </article>


    I did exactly what You have written. Result using DSSSL stylescheet:

    <DIV CLASS="glosslist">
    <DL>A procedural programming language invented by K&R.
    </DL>
    </DIV

    and result using XSL stylescheet:

    <div class="glosslist">
    <dl>
    <dt></dt>
    </dl>
    </div>

    I think, the problem is cos we redefine only DTD of glosslist elements
    but not behaviour of it. So xml:

    <glossentry term="C">...</glossentry>

    is valid against DTD, but XSL / DSSSL styles could not correctly
    translate this XML.


    --
    /// Szymon Nieradka
    /// http://microbus.pl
    Szymon Nieradka, May 12, 2006
    #3
  4. Szymon Nieradka wrote:
    > <xsl:call-template name="glossentry"/>


    1) You did modify the template you're trying to call so it too has
    name="glossentry", right?

    2) Will its behavior be correct when it's invoked on this node? I'd bet
    it recurses downward and so will *not* do what you intend.

    Suggestion: Copy the existing template for the standard glossentry, make
    the new copy match="glossEntry", and modify its behavior appropriately.
    You may (or may not) need to copy in some of the behavior from the
    glossdef and para templates as well, since you aren't going to be going
    through those.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, May 12, 2006
    #4
  5. Szymon Nieradka

    Peter Flynn Guest

    Szymon Nieradka wrote:
    > I did exactly what You have written. Result using DSSSL stylescheet:
    >
    > <DIV CLASS="glosslist">
    > <DL>A procedural programming language invented by K&R.
    > </DL>
    > </DIV
    >
    > and result using XSL stylescheet:
    >
    > <div class="glosslist">
    > <dl>
    > <dt></dt>
    > </dl>
    > </div>
    >
    > I think, the problem is cos we redefine only DTD of glosslist elements
    > but not behaviour of it. So xml:
    >
    > <glossentry term="C">...</glossentry>
    >
    > is valid against DTD, but XSL / DSSSL styles could not correctly
    > translate this XML.


    XSL and DSSSL that you write will have no problems handling that DTD.

    I think what you mean is that the *pre-written* XSL/DSSL DocBook
    stylesheets won't handle it. Not surprising: they were written
    for the unmodified DTD.

    But you said you were using custom XSL. Just edit it to reflect the
    DTD changes.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, May 13, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Durzi

    Performance of Xsl Transformations

    George Durzi, Dec 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    3,509
    George Durzi
    Dec 31, 2003
  2. Franck Perrin
    Replies:
    0
    Views:
    1,069
    Franck Perrin
    Jul 14, 2003
  3. Antonio Amato
    Replies:
    2
    Views:
    1,256
    Michael Wiedmann
    Nov 18, 2004
  4. Replies:
    1
    Views:
    510
    Joseph Kesselman
    Nov 27, 2007
  5. Geico Caveman
    Replies:
    0
    Views:
    520
    Geico Caveman
    Oct 2, 2008
Loading...

Share This Page