Entity declaration in DTD

Thomas Sommer

Usenet Archive
Joined
Aug 29, 2004
Messages
20
Reaction score
0
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
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
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
 

Thomas Sommer

Usenet Archive
Joined
Aug 29, 2004
Messages
20
Reaction score
0
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
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
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

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top