Search code examples
htmlcssxsltxsl-foapache-fop

XSLT adds unwanted linebreaks


Im trying to generate HTML output with xslt and for that i use the Apache Formatting Objects Processor Version 2.3.

Each <text> element in the input file represents a line on a DIN A4 Page so the following input is a sentence that extends over 2 lines:

<text>This is a longer text where every line will be written into a span html element and somehow there will</text>
<text>be added a line break where there is none</text>

My XSLT template looks like:

<xsl:template match="text">
  <div>
    <span>
        <xsl:value-of select="."/>
    </span>
  </div>
</xsl:template>

The desired output is:

<div><span>This is a longer text where every line will be written into a span html element and somehow there will</span></div>
<div><span>be added a line break where there is none</span></div>

But what i get is:

<div><span>This is a longer text where every line will be written into a span html element and
                  somehow there will</span></div>
<div><span>be added a line break where there is none</span></div>

My css:

div {
  position: absolute;
  white-space: nowrap;
  border: 1px solid black;
}
span {
  white-space: pre;
}

As i am using css for my span styling with the property white-space: pre; this looks pretty weird in the output as the somehow there will is somewhere in between those word of the second line.


Solution

  • You could try (assuming an XSLT 3 processor like Saxon 9.8 or later) to use <xsl:output method="html" suppress-indentation="span"/>.