[英]using xslt stylesheet to convert xhtml blank lines to an XSL-FO blank line
I'm using an XSLT stylesheet (by Antennahouse) to convert XHTML to an XSL-FO file. 我正在使用XSLT样式表(由Antennahouse)将XHTML转换为XSL-FO文件。 I defined a blank line in my XHTML file as 2 consecutive HTML BR tags.
我在我的XHTML文件中将一个空行定义为2个连续的HTML BR标记。 Now there is no native support for a blank line in the XSL-FO format.
现在,XSL-FO格式的空白行没有原生支持。 I want to work around this limitation by adding a height to the fo:block that the stylesheet inserts for a BR tag.
我想通过在样式表为BR标记插入的fo:block中添加一个高度来解决这个限制。 However I'm new to the XSLT language and I'm having some problems doing this.
但是,我是XSLT语言的新手,我在这方面遇到了一些问题。
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.) 我可以弄清楚如何为我遇到的每个BR标签插入这个高度,但我只想在彼此之后有2个BR标签时插入空白行(否则在每个文本后面都会插入一个空行,然后是BR标签。)
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". 我得到了一个“无意义”的表达式(11大于10),它将定义何时插入常规的fo:block或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.
显然这个表达没有意义,应该检查的是这个BR元素是否是连续的第二个元素。 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 > 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. 为了便于参考,这是一个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>
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]
): 匹配只有那些
<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>
and throw away those <br>
s that are directly preceded by a <br>
, to avoid doubling the space-after. 和扔掉那些
<br>
直接由一个前面小号<br>
,避免了空间后加倍。 By matching them with an empty template they are effectively deleted: 通过将它们与空模板匹配,它们将被有效删除:
<xsl:template match="html:br[preceding-sibling::*[1][self::html:br]]" />
I was playing around with the same idea of multiple line breaks. 我正在玩多个换行符的想法。
<xsl:template match="html:br">
<fo:block linefeed-treatment="preserve">
<xsl:text> </xsl:text>
</fo:block>
</xsl:template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.