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