DocBook custom XSL transformations

S

Szymon Nieradka

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?
 
P

Peter Flynn

Szymon said:
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
 
S

Szymon Nieradka

Peter said:
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.
 
J

Joe Kesselman

Szymon said:
<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.
 
P

Peter Flynn

Szymon said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top