【发布时间】:2018-04-04 10:18:54
【问题描述】:
我正在学习 xsl:fo 并使用 w3schools 上的 xml 示例文件进行培训:https://www.w3schools.com/xml/cd_catalog.xml,我对其进行了一些修改以添加“图片”标签。
我使用xsl:for-each、fo:table 和fo: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