Question

I need to output some hex-data with some bytes highlighted with colored background. Bytes in the data that represent red color values should have red background. That's why I chose

<emphasis role="red"></emphasis>

to be the tag of choice.

HTML output

For HTML output I use

  <xsl:param name="emphasis.propagates.style" select="1"/>

in the xsl file and

.red {
  background-color: red;
}

in the stylesheet. This works flawlessly.

PDF output

For PDF output I use dblatex and tried (file fo.xsl)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:d="http://docbook.org/ns/docbook"
    xmlns="http://www.w3.org/TR/xhtml1/transitional"
    version="1.0">

  <xsl:param name="draft.mode">no</xsl:param>
  <xsl:param name="imagedata.default.scale">maxwidth=12cm</xsl:param>

  <xsl:template match="emphasis[@role='red']">
    <xsl:param name="content">
      <xsl:apply-templates/>
    </xsl:param>
    <xsl:text>{\color{red}</xsl:text>
    <xsl:copy-of select="$content"/>
    <xsl:text>}</xsl:text>
  </xsl:template>

</xsl:stylesheet>

And (file test.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
  "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
<article lang="en">
  <title>Test</title>
  <para>
    <screen>0240h: 00 20 <emphasis role="red">00</emphasis> 21</screen>
  </para>
</article>

With the following command to build latex source for checking:

dblatex --backend=pdftex --xslt=xsltproc \
    --input-format=xml --type=tex \
    --xsl-user=fo.xsl --verbose --output=test.tex test.xml

This does not work. Emphasised text is still italic, as shown in an excerpt from the resulting test.tex:

\begin{lstlisting}[firstnumber=1,escapeinside={<t>}{</t>},moredelim={**[is][\bfseries]{<b>}{</b>}},moredelim={**[is][\itshape]{<i>}{</i>}},]
0240h: 00 20 <i>00</i> 21\end{lstlisting}

What am I doing wrong?

Was it helpful?

Solution

As mzjn stated, the screen tag was a problem. After reading the linked resource, the final template that works for me in this case, and produces output similar to the html look, is this:

<xsl:template match="emphasis[@role='red']" mode="latex.programlisting">
  <xsl:param name="co-tagin" select="'&lt;:'"/>
  <xsl:param name="rnode" select="/"/>
  <xsl:param name="probe" select="0"/>
  <xsl:param name="content">
    <xsl:apply-templates/>
  </xsl:param>
  <xsl:text>&lt;t&gt;\colorbox{red}{</xsl:text>
  <xsl:copy-of select="$content"/>
  <xsl:text>}&lt;/t&gt;</xsl:text>
</xsl:template>

which leads to the following latex output:

\begin{lstlisting}[firstnumber=1,escapeinside={<t>}{</t>},moredelim={**[is][\bfseries]{<b>}{</b>}},moredelim={**[is][\itshape]{<i>}{</i>}},]
0240h: 00 20 <t>\colorbox{red}{00}</t> 21\end{lstlisting}

Maybe it would be better to add another moredelim to lstlisting than using the escapeinside, but with this solution, this question is answered for me.

OTHER TIPS

You are using dblatex, which is a tool (a set of XSLT stylesheet modules) that produces PDF output from DocBook where the intermediate format is LaTeX rather than XSL-FO. So in order to customize the look and feel of inline text (such as emphasis), you have to use LaTeX. The following template should work for you:

<xsl:template match="emphasis[@role='red']">
  <xsl:param name="content">
    <xsl:apply-templates/>
  </xsl:param>
  <xsl:text>{\color{red}</xsl:text>
  <xsl:copy-of select="$content"/>
  <xsl:text>}</xsl:text>
</xsl:template>

Note that it says emphasis (without a d: prefix). dblatex strips out the namespace from DocBook 5 source documents at the start of the transformation, so there should be no namespaces in customizations either.


The fact that the emphasis occurs within screen (which is a "verbatim" element; see http://dblatex.sourceforge.net/doc/manual/sec-verbatim.html) makes things more complicated. My customization suggestion does work if the screen start and end tags are removed from your sample para.

If bold text instead of red-coloured is an acceptable compromise, you can use the following in your XML document:

<screen>0240h: 00 20 <emphasis role="bold">00</emphasis> 21</screen>

No customization is needed for this to work. role="bold" is handled by the default dblatex stylesheets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top