xml - XSL FO: Print Just A Single Blank Line Between Paragraphs -
i have xml data , xsl fo stylesheet format xml. have following xml document:
<content> <para>paragraph one.</para> <para /> <para>paragraph two.</para> <para /> <para>paragraph three.</para> </content>
the desired output after styling fo stylesheet be:
paragraph one. paragraph two. paragraph three.
the actual output getting below, there 2 blank lines.
paragraph one. paragraph two. paragraph three.
the stylesheet code using is:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:fo="http://www.w3.org/1999/xsl/format"> <xsl:variable name="newline"> <xsl:text> </text> </xsl:variable> <xsl:template match="/"> <fo:root> <fo:layout-master-set> <fo:simple-page-master master-name="pagesetup"> <fo:region-body region-name="xsl-region-body" /> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="pagesetup"> <fo:flow flow-name="xsl-region-body"> <fo:block> <xsl:apply-templates /> </fo:block> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> <xsl:template match="para"> <fo:block linefeed-treatment="preserve" white-space-collapse="false"> <xsl:choose> <xsl:when test="text() != ''"> <xsl:value-of select="text()" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$newline" /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
the conventional way space between blocks use space-before
(https://www.w3.org/tr/xsl11/#space-before) and/or space-after
(https://www.w3.org/tr/xsl11/#space-after) properties.
if going persist empty para
elements in xml, can ignore them , use space-after
replacing template para
with:
<xsl:template match="para[text()]"> <fo:block space-after="1em"> <xsl:apply-templates /> </fo:block> </xsl:template>
Comments
Post a Comment