using xslt stylesheet to convert xhtml blank lines to an XSL-FO blank line

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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> 

回答1:

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]]" /> 


回答2:

I was playing around with the same idea of multiple line breaks.

<xsl:template match="html:br">    <fo:block linefeed-treatment="preserve">     <xsl:text>&#10;</xsl:text>   </fo:block> </xsl:template> 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!