2010-02-24 78 views
6

我使用XSLT样式表(由Antennahouse)将XHTML转换为XSL-FO文件。我在我的XHTML文件中将空白行定义为2个连续的HTML BR标签。现在,对XSL-FO格式的空行没有本地支持。我想通过向样式表插入BR标记的fo:块添加高度来解决此限制。不过,我是XSLT语言的新手,我在做这件事时遇到了一些问题。使用xslt样式表将xhtml空行转换为XSL-FO空行

我可以弄清楚如何为我遇到的每个BR标签插入这个高度,但是我只希望在有两个BR标签之后插入空白行(否则在每个文本之后都会插入一个空行)然后是一个BR标签)

我得到了一个'无意义'的表达式(11大于10),它将定义何时插入一个普通的fo:block或一个fo:block与space-after = “1EM”。显然,这种表达方式没有意义,它应该检查的是BR元素是否是连续的第二个元素。如果有人能够帮助我,或者指引我朝着正确的方向发展,那么我将不胜感激。 这就是我现在所拥有的:

<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> 

以供参考,这是一块XHTML的,我想双BR标签将被改造成一个空行,但单BR标签应该只是一个常规的换行符。

    <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> 

回答

4

沿着这个东西线。

只匹配那些<br> s表示直接后跟一个元件(following-sibling::*[1]),其本身是一个<br>[self::html:br]):

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

和扔掉那些<br> s表示直接由一个<br>之前,以避免使空间翻倍。通过将它们与空模板进行匹配,它们被有效删除:

<xsl:template match="html:br[preceding-sibling::*[1][self::html:br]]" /> 
+0

非常好,即时工作。谢谢! – 2010-02-24 17:45:50

+0

@Bas:不客气。 :)好问题,顺便说一句。 – Tomalak 2010-02-24 19:14:34

0

我当时在玩多个换行符的想法。

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