<indexterm> element causes extra whitespace in PDF

Here should go questions about transforming XML with XSLT and FOP.
ahiggins
Posts: 12
Joined: Mon Jun 06, 2022 10:10 pm

<indexterm> element causes extra whitespace in PDF

Post by ahiggins »

Hi,
I'm not sure if this is the right place to ask or if you can direct me to another forum. I use Oxygen XML v.24 with DITA-OT3.7 and use XSL FO to transform PDFs. When a paragraph (<p> element) contains only <indexterm> elements, it creates a whitespace in the PDF output. For the following example, a line of whitespace appears between the short description and the first paragraph.

Code: Select all

<concept id="lawnmowerconcept" xml:lang="en-us">
  <title>Lawnmower</title>
  <shortdesc>The lawnmower is a machine used to cut grass in the yard.</shortdesc>
  <conbody>
    <p><indexterm>indexterm</indexterm></p>
    <p>Lawnmowers can be electric, gas-powered, or manual.</p>
  </conbody>
</concept>
I looked at the index.xsl file in the org.dita.pdf2 plugin but I can't figure out if I need to make a change to that file or different one. I appreciate any help.

Thanks,
Amy
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: <indexterm> element causes extra whitespace in PDF

Post by Radu »

Hi Amy,

How about if the paragraph is empty, without indexterm inside it?
Because I would also expect an empty paragraph (with no text or elements inside it) to produce some kind of extra space there, as each paragraph has certain margins.
How about if you define the index terms in the topic prolog section instead of creating extra paragraphs just to define them?
For the Oxygen User's Manual we usually define them in the prolog section like:

Code: Select all

<topic id="preferences-xml">
  <title>XML Preferences</title>
  <prolog>
    <metadata>
      <keywords><indexterm>Preferences</indexterm></keywords>
    </metadata>
  </prolog>
  <body>
    <p>This section describes the panels that contain the user preferences related with XML.</p>
  </body>
</topic>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: <indexterm> element causes extra whitespace in PDF

Post by chrispitude »

If you have too many <indexterm>-in-<p> instances in your content to fix manually, you could create a refactoring operation to move them to a <prolog> element for you.

If you are not sure how to do this, I can help.
ahiggins
Posts: 12
Joined: Mon Jun 06, 2022 10:10 pm

Re: <indexterm> element causes extra whitespace in PDF

Post by ahiggins »

Thanks to both of you for your help. We do want to keep our indexterms in separate paragraphs for specific situations because it gives the option to link a group of indexterms to a location in the middle of a page.
So far, this xsl code seems to solve the issue of blank lines caused by <p> elements consisting only of <indexterms>.

Code: Select all

<xsl:template match="*[contains(@class, ' topic/p ')]">
      <xsl:if test="child::*/@class | child::text()">
         <fo:block xsl:use-attribute-sets="p">
            <xsl:call-template name="commonattributes"/>
            <xsl:apply-templates/>
         </fo:block>
      </xsl:if>
   </xsl:template>
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: <indexterm> element causes extra whitespace in PDF

Post by Radu »

Hi,
I'm not sure how a condition like this child::*/@class would help as it also matches an <indexterm> element as all DITA elements have @class attributes defined on them.
Maybe leave that template which matches the paragraph as it originally was and add an extra template which ignores all paragraphs which have no text and have all child elements with name "indexterm":

Code: Select all

<xsl:template match="*[contains(@class, ' topic/p ')][string-length(string-join(text(), '')) = 0][count(*) = count(*[local-name()='indexterm'])]"/>
But is that specific indexterm taken into account anymore in the generated PDF if we filter it out in this stage?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply