【问题标题】:xsl fo center a table and an image using display-align="center"xsl fo 使用 display-align="center" 使表格和图像居中
【发布时间】:2018-04-04 10:18:54
【问题描述】:

我正在学习 xsl:fo 并使用 w3schools 上的 xml 示例文件进行培训:https://www.w3schools.com/xml/cd_catalog.xml,我对其进行了一些修改以添加“图片”标签。

我使用xsl:for-eachfo:tablefo:external-graphic 解析文件以在表格中收集每张CD 的信息。正如前面问题中所建议的,我对它们都使用了display-align="center",但它不起作用:图像和表格保持在左侧对齐。

这是一个代码示例(我删除了大部分样式属性以使其更具可读性):

<xsl:for-each select="CATALOG/CD">              

            <fo:block text-align="center">
                <xsl:value-of select="TITLE"/> - <xsl:value-of select="ARTIST"/>
            </fo:block>

            <fo:block>
                <fo:external-graphic content-height="scale-to-fit" width="2.00in" content-width="2.00in" display-align="center">
                    <xsl:attribute name="src">pictures/<xsl:value-of select="PICTURE"/>.jpg</xsl:attribute>
                </fo:external-graphic>
            </fo:block>

            <fo:table table-layout="fixed" font-family="Helvetica" text-indent="2em" space-before="2em" display-align="center">
                <fo:table-column column-width="4cm"/>
                <fo:table-column column-width="4cm"/>                   
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell><fo:block>Country :</fo:block></fo:table-cell>
                        <fo:table-cell><fo:block><xsl:value-of select="COUNTRY"/></fo:block></fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell><fo:block>Company :</fo:block></fo:table-cell>
                        <fo:table-cell><fo:block><xsl:value-of select="COMPANY"/></fo:block></fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell><fo:block>Price :</fo:block></fo:table-cell>
                        <fo:table-cell><fo:block><xsl:value-of select="PRICE"/></fo:block></fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell><fo:block>Year :</fo:block></fo:table-cell>
                        <fo:table-cell><fo:block><xsl:value-of select="YEAR"/></fo:block></fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>

        </xsl:for-each>

【问题讨论】:

  • 你试过 text-align="center" 吗?您正在左/右对齐。它将适用于图像但不适用于表格,您需要做更多的工作。
  • 我当时确实在图像上尝试了 text-align,它确实有效,是的 :)

标签: image centering xsl-fo apache-fop xmltable


【解决方案1】:

display-align="center" 用于垂直居中(即在块进度方向上)。见https://www.w3.org/TR/xsl/#display-align。 (另外,display-align 不适用于 fo:table。如果您确实想将表格垂直居中,则必须在 包含fo:table 的 FO 上使用 display-align="center" .)

对于左右居中(在 inline-progression-direction 中),使用text-align="center":见https://www.w3.org/TR/xsl/#text-align

但是,text-align 不适用于fo:table,因此您需要将其放在fo:table-and-caption 上并将fo:table 作为fo:table-and-caption 的子级(而fo:table-caption 是可选的)。见https://www.w3.org/TR/xsl/#fo_table-and-caption

【讨论】:

  • text-align 非常适合我的图像,谢谢!但是,当我将表格放入 标签时,我的表格没有显示在 pdf 上(tehre 什么都没有)(我尝试过没有任何样式,现在根本没有 text-align)跨度>
  • 我使用 fop。我的 xsl:fo 标签在 xsl 文档中(命令行:fop -xml cd_catalog.xml -xsl cd_catalogfo.xsl -pdf cd_catalog.pdf)
  • 我意识到我确实有一个警告:“Apache FOP 尚未实现以下功能:fo:table-and-caption”
  • 然后将fo:table 放在fo:block 中。
猜你喜欢
  • 1970-01-01
  • 2013-11-04
  • 1970-01-01
  • 2018-07-16
  • 1970-01-01
  • 1970-01-01
  • 2021-05-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多