Search code examples
xsltdocbook

how can i change the html rendering of d:formalpara


This is how the default configuration renders a formalpara:

this:

<formalpara>
  <title>foo</title>
  <para>bar</para>
</formalpara>

will be rendered as this:

<p>
  <span class="formalpara-title">foo</span>
  bar
</p>

I already set <xsl:param name="runinhead.default.title.end.punct"></xsl:param> so the stupid point doesnt get rendered anymore.

This is what i actually want:

<div class="formalpara">
  <h2 class="title">foo</h2>
  <p>bar</p>
</div>

This is what i've done so far:

I changed:

<xsl:template match="d:formalpara">
  <xsl:call-template name="paragraph">

.....

</xsl:template>

to:

<xsl:template match="d:formalpara">
  <xsl:call-template name="block.object">

.....

</xsl:template>

and I changed:

<xsl:template match="d:formalpara/d:title|d:formalpara/d:info/d:title">

.....

  <span class="formalpara-title">

  .....

  </span>
</xsl:template>

to:

<xsl:template match="d:formalpara/d:title|d:formalpara/d:info/d:title">

.....

  <h2 class="title">

  .....

  </h2>
</xsl:template>

This is what will be rendered now:

<div class="formalpara">
  <h2 xmlns:d="http://docbook.org/ns/docbook" class="title">foo</h2>
  bar
</div>

What is my actual Question?

  1. Why is the xmlns:d="http://docbook.org/ns/docbook" getting rendered?
  2. How can I get the <p> tag around my bar?

Solution

  • You should be able to avoid the namespace declaration xmlns:d="http://docbook.org/ns/docbook" on the h2 element by adding exclude-result-prefixes="d" on your xsl:stylesheet (respectively xsl:transform) element.

    I would assume that adding

    <xsl:template match="d:formalpara/d:para">
      <p>
        <xsl:apply-templates/>
      </p>
    </xsl:template>
    

    ensures the transformation of the para element child of a formalpara, but I haven't checked whether that works.