views:

325

answers:

1

Hello,

I'm using an XSLT stylesheet (by Antennahouse) to convert XHTML to an XSL-FO file. I defined a blank line in my XHTML file as 2 consecutive HTML BR tags. Now there is no native support for a blank line in the XSL-FO format. I want to work around this limitation by adding a height to the fo:block that the stylesheet inserts for a BR tag. However I'm new to the XSLT language and I'm having some problems doing this.

I can figure out how to insert this height for every BR tag I encounter, but I only want the blank line to be inserted when there are 2 BR tags after each other (otherwise a blank line would be inserted after every text followed by a BR tag.)

I got as far as making a 'nonsense' expression (11 is greater than 10) which will define when to insert a regular fo:block or an fo:block with space-after="1em". Obviously this expression makes no sense, what it should check on is whether this BR element is the second one in a row. If anyone could help me out here or point me in the right direction, it would be greatly appreciated. This is what I have right now:

<xsl:template match="html:br">
<xsl:choose>
    <xsl:when test="11 &gt; 10">
        <fo:block space-after="1em">
            <xsl:call-template name="process-common-attributes"/>
        </fo:block>
    </xsl:when>
    <xsl:otherwise>
        <fo:block>
            <xsl:call-template name="process-common-attributes"/>
        </fo:block>
    </xsl:otherwise>
  </xsl:choose>

For reference sake, this is a piece of XHTML where I want the double BR tags to be transformed into a blank line, but the single BR tags should simply be a regular line break.

                  <div style="color: #000000; font-family: arial; font-size: 10pt; font-style: normal; font-weight: normal;">
                    <span>description</span>
                    <br/>
                    <span>using</span>
                    <br/>
                    <span>multiple</span>
                    <br/>
                    <span>lines</span>
                    <br/>
                    <br/>
                    <span>with</span>
                    <br/>
                    <br/>
                    <span>blank</span>
                    <br/>
                    <br/>
                    <span>lines</span>
                    <br/>
                </div>
+2  A: 

Something along the lines of this.

Match only those <br>s that are directly followed by an element (following-sibling::*[1]) that itself is a <br> ([self::html:br]):

<xsl:template match="html:br[following-sibling::*[1][self::html:br]]">
  <fo:block space-after="1em" />
</xsl:template>

and throw away those <br>s that are directly preceded by a <br>, to avoid doubling the space-after. By matching them with an empty template they are effectively deleted:

<xsl:template match="html:br[preceding-sibling::*[1][self::html:br]]" />
Tomalak
Excellent, that worked instantly. Thank you!
Bas van den Broek
@Bas: You are welcome. :) Good question, BTW.
Tomalak