Entity declaration in DTD

T

Thomas Sommer

Hi,

I want to use formulas in docbook and use the following for
inlineequations.

Text
<inlineequation><inlinemediaobject><imageobject>
<imagedata fileref="1.png"/></imageobject></inlinemediaobject>
<alt role="tex">\vec{A}</alt></inlineequation>
Text

Now this is hard to read unlike in TEX: Text &\vec{A}$ Text.
So I thought I would define some entities in my DTD that would
replace everything except the data I have type so it would look
something like this:

Text &e1;1.png&e2;\vec{A}&e3; Text

Now this does not work and even a simple thing like

<!ENTITY pb "<para>">
<!ENTITY pe "</para>">

Use like
&pb;TEXT&pe;

gives:

Entity: line 1: parser error : Premature end of data in tag para line 1
<para>

Looks like it wants to parse the entity itself. Would there be a way to
avoid this.

Thanks Thomas
 
R

Richard Tobin

Thomas Sommer said:
<!ENTITY pb "<para>">
<!ENTITY pe "</para>">

Unfortunately entities have to be balanced with respect to elements,
so you can't do this sort of thing.

If you're doing a lot of this, you could define your own XML syntax
and a stylesheet that converts it to the docbook format. For example,
you could use

<eqn image="1.png" tex="\vec{A}"/>

and have the stylesheet transform that to
<inlineequation><inlinemediaobject><imageobject>
<imagedata fileref="1.png"/></imageobject></inlinemediaobject>
<alt role="tex">\vec{A}</alt></inlineequation>

with a template like

<xsl:template match="eqn">
<inlineequation>
<inlinemediaobject>
<imageobject>
<imagedata fileref="{@image}"/>
</imageobject>
</inlinemediaobject>
<alt role="tex"><xsl:value-of select="@tex"/></alt>
</inlineequation>
</xsl:template>

-- Richard
 
T

Thomas Sommer

I just got the same idea but I was puzzled that one can put this
in the stylesheet. And if I do that I only get the value of the
"tex" entry. Not more not less.
The command line I use:

xsltproc -o test.tex ~/xml/tex.xsl doc.xml

The beginning of tex.xsl looks like this:

<?xml version='1.0' encoding="ISO-Latin-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="http://db2latex.sourceforge.net/xsl/docbook.xsl"/>

<xsl:template match="eqn">
<equation>
<mediaobject>
<imageobject>
<imagedata fileref="{@image}"/></imageobject>
</mediaobject>
<alt role="tex"><xsl:value-of select="@tex"/></alt>
</equation>
</xsl:template>

I am not sure but in my understanding the
stylefile can only convert my xml-file into some other format. So the
"replacement" of the eqn should happen before using the style. Thus I
think one should do something like

<xsl:template match="eqn">
<xsl:text>\begin{equation}</xsl:text>
<alt role="tex"><xsl:value-of select="@tex"/></alt>
<xsl:text>\end{equation}</xsl:text>
</equation>
</xsl:template>

And adapt the style sheet for the html-output the same way. But this is not
very handy.

Thomas
 
R

Richard Tobin

Thomas Sommer said:
The beginning of tex.xsl looks like this:

<?xml version='1.0' encoding="ISO-Latin-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="http://db2latex.sourceforge.net/xsl/docbook.xsl"/>

<xsl:template match="eqn">

I wasn't suggesting that you combine it with the docbook stylesheet,
but that you have a completely separate stylesheet that you run
beforehand. Its output would be vanilla docbook with <equation>
elements and so on. The you would run the docbook stylesheet on that.

As well as the template I posted, the stylesheet would have to have
an identity template to pass the rest of the document through
unchanged:

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

-- Richard
 

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

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top