繁体   English   中英

使用xslt样式表将xhtml空行转换为XSL-FO空行

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

我正在使用XSLT样式表(由Antennahouse)将XHTML转换为XSL-FO文件。 我在我的XHTML文件中将一个空行定义为2个连续的HTML BR标记。 现在,XSL-FO格式的空白行没有原生支持。 我想通过在样式表为BR标记插入的fo:block中添加一个高度来解决这个限制。 但是,我是XSLT语言的新手,我在这方面遇到了一些问题。

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

我得到了一个“无意义”的表达式(11大于10),它将定义何时插入常规的fo:block或fo:block with 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>

有点像这样的东西。

匹配只有那些<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>直接由一个前面小号<br> ,避免了空间后加倍。 通过将它们与空模板匹配,它们将被有效删除:

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM