使用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:块添加高度来解决此限制。不过,我是XSLT语言的新手,我在做这件事时遇到了一些问题。
我可以计算出如何为每个遇到的BR标签插入这个高度,但我只希望在有两个BR标签之后插入空行(否则会在每个文本后面插入一个空白行,然后是BR标签。)
我做了一个无意义的表达式(11大于10 ),它将定义何时插入一个常规的fo:block或一个带有space-after =1em的fo:block。显然,这种表达方式没有意义,它应该检查的是BR元素是否是连续的第二个元素。如果有人能够帮助我,或者指引我朝着正确的方向发展,那么我将不胜感激。
这就是我现在的情况:
< xsl:template match =html:br>
< 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>
一块XHTML,我希望将双BR标签转换为空行,但单个BR标签应该只是一个普通的换行符。
< div style =color:#000000; font-family:arial; font-size:10pt; font-style:normal; font-weight:normal;>
< span>说明< / span>
< br />
< span>使用< / span>
< br />
< span>多个< / span>
< br />
< span>行< / span>
< br />
< br />
< span>与< / span>
< br />
< br />
< span>空白< / span>
< br />
< br />
< span>行< / span>
< br />
< / div>
只匹配那些紧跟元素( following-sibling:)的
)本身是< br>
( [self :: html:br]
):
< xsl:template match =html:br [following-sibling :: * [1] [自:: HTML:BR]]>
< fo:block space-after =1em/>
< / xsl:template>
并扔掉那些< br>
直接在< br>
之前,以避免将空格加倍。通过将它们与空模板进行匹配,它们被实际删除:
< xsl:template match =html:br [ sibling :: * [1] [self :: html:br]]/>
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 > 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>
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]]" />
这篇关于使用xslt样式表将xhtml空行转换为XSL-FO空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!