【问题标题】:XSL-FO: Adjust border-width based on text widthXSL-FO:根据文本宽度调整边框宽度
【发布时间】:2018-05-23 20:33:59
【问题描述】:

我在使用 Apache FOP 作为处理器时遇到了 XSL-FO 问题。我有一个简单的样式表,并且已经为 fo:block-container 设置了一个圆形边框。问题是:文本大小是不可预测的,因为 .fo 文件将使用 XSLT 和 XML 生成,所以我需要告诉 FOP 根据文本宽度调整边框宽度,而不是应用相同的宽度所有的容器。有什么想法吗?

在 XSLT 文件中:

    <fo:block-container xsl:use-attribute-sets="right-side-itens">
        <fo:block-container xsl:use-attribute-sets="rounded-borders">                                    
            <fo:block>
                <xsl:value-of-select="./tagInsideXML/@attribute" />
                <!-- qwertyuiopasdfghjkl -->
            </fo:block>
        </fo:block-container>
    <fo:block-container>

`

在styles.xsl 外部文件中:

<xsl:attribute-set name="right-side-itens">
    <xsl:attribute name="top">35px</xsl:attribute>
    <xsl:attribute name="right">45px</xsl:attribute>
    <xsl:attribute name="text-align">end</xsl:attribute>
    <xsl:attribute name="font-size">10px</xsl:attribute>
    <xsl:attribute name="height">10cm</xsl:attribute>
    <xsl:attribute name="width">200px</xsl:attribute>
    <xsl:attribute name="position">absolute</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="rounded-borders">
    <xsl:attribute name="margin-top">2px</xsl:attribute>
    <xsl:attribute name="margin-right">1.8px</xsl:attribute>
    <xsl:attribute name="padding-right">2px</xsl:attribute>
    <xsl:attribute name="float">right</xsl:attribute>
    <xsl:attribute name="line-height">18px</xsl:attribute>
    <xsl:attribute name="font-size">8px</xsl:attribute>
    <xsl:attribute name="border">solid 1.2px #000000</xsl:attribute>
    <xsl:attribute name="fox:border-radius">6px</xsl:attribute>
    <xsl:attribute name="position">relative</xsl:attribute>
    <xsl:attribute name="overflow">visible</xsl:attribute>
</xsl:attribute-set>

Here is a sample image showing the desired output

【问题讨论】:

  • 您能否提供更多详细信息,例如示例 XSL-FO 或屏幕截图以及当前问题的说明?
  • 您好,我添加了一个示例代码和一个经过编辑的图像来阐明我的目标。提前致谢。

标签: xml xslt xsl-fo apache-fop


【解决方案1】:

块容器通常具有固定大小,而块可以随其内容增长。所以我会在容器内放置一个 fo:block,并将边框应用于该块。

【讨论】:

  • 已经尝试过了,发生的情况是边框总是将其宽度调整为包含 fo:block 的最大标签,因此例如将边框应用于 fo:container 内的 fo:block使边框宽度与 fo:container 宽度相同,但将 fo:container 关闭,您会看到现在边框宽度与 fo:region-body 中的相同。
  • 我的开发机器现在手边没有,但你可以检查一下 fo:inline 是否支持边框...
  • 它们确实支持边框,但宽度仍然适合最大的容器。
猜你喜欢
  • 2014-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多