gpt4 book ai didi

xslt - XSL-FO 引线包装

转载 作者:行者123 更新时间:2023-12-04 23:21:34 25 4
gpt4 key购买 nike

我有一个数据列表,其中有一个虚线前导分隔文本,左对齐和右对齐。我正在使用以下 XSL-FO 来实现这一点。

<fo:block text-align-last="justify">
<xsl:value-of select="left-text"/>
<fo:leader leader-pattern="dots"/>
<xsl:value-of select="right-text"/>
</fo:block>

Some text on the left............................some text on the right


当文本全部适合一行时,这非常有效。我遇到的问题是正确处理右侧的文本如何换行。我有一个特定的要求,将它的格式设置为与右侧对齐的换行文本,如下所示:

Some text on the left.................a long piece of text on the right                                                        that has wrapped


我试图通过领导者和 table 来实现这一目标,但无济于事。我正在使用 Antenna House 格式化程序。非常欢迎任何建议。
谢谢你的帮助。

最佳答案

以此为灵感并制定自己的规则:

       <fo:block text-align="justify" text-align-last="right">
<fo:inline>Some text on the left</fo:inline>
<fo:leader leader-pattern="dots" leader-length.minimum="2in" leader-length.optimum="2in" leader-length.maximum="3in"/>
<fo:inline>a long piece of text on the right that has wrapped</fo:inline>
</fo:block>
<fo:block text-align="justify" text-align-last="right">
<fo:inline>Some text</fo:inline>
<fo:leader leader-pattern="dots" leader-length.minimum="2in" leader-length.optimum="2in" leader-length.maximum="3in"/>
<fo:inline>a long piece of text on the right that has wrapped and is even longer</fo:inline>
</fo:block>

您唯一无法停止的是右手线太长以至于它位于点下方,但您没有将其指定为要求。如果是这样,恐怕没有解决方案。此外,如果一行太短,它将右对齐。您必须使用最小/最大值来仅强制换行。

如果您知道字体大小,您可以计算左/右元素中的字符数,然后根据总字符数调用您的模板或此示例。

Result of this FO

对于计数,您可以执行类似此模板的操作,其中“50”个字符可以通过引线长度进行调整以获得正确的结果。
<xsl:template name="processitem">
<xsl:choose>
<xsl:when test="string-length(left) + string-length(right) > 50">
<fo:block text-align="justify" text-align-last="right">
<fo:inline><xsl:value-of select="left"/></fo:inline>
<fo:leader leader-pattern="dots" leader-length.minimum="2in" leader-length.optimum="2in" leader-length.maximum="4in"/>
<fo:inline><xsl:value-of select="right"/></fo:inline>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block text-align-last="justify">
<fo:inline><xsl:value-of select="left"/></fo:inline>
<fo:leader leader-pattern="dots"/>
<fo:inline><xsl:value-of select="right"/></fo:inline>
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

使用一些示例数据,我得到了这个渲染:

Using Template Above with Sample Data

关于xslt - XSL-FO 引线包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24872718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com