作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将我的数据和表格放在页面的中心,如下表所示。但我只做了表格的东西,剩下的数据对齐和调整我不能做,因为我不熟悉 xsl。
这是我的 xsl 代码:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="iso-8859-1" />
<xsl:template match ="records">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="list">
<fo:region-body></fo:region-body>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="list">
<fo:flow flow-name="xsl-region-body">
<fo:block text-align="right">
<fo:table >
<fo:table-body>
<xsl:for-each select="./list">
<xsl:if test="position()<= 1">
<fo:table-row>
<xsl:for-each select="./item">
<fo:table-cell text-align="center"
width="100px" border-color="black" border="2px">
<fo:block color="green" font-family="monospace"
font-size="10pt" padding="5pt" space-before="5pt" space-after="5pt">
<xsl:attribute name="color">
<xsl:choose>
<xsl:when test="position() = 1 ">
<xsl:text>black</xsl:text>
</xsl:when>
<xsl:when test="position() = 2 ">
<xsl:text>#333399</xsl:text>
</xsl:when>
<xsl:when test="position() = 3 ">
<xsl:text>#FF9900</xsl:text>
</xsl:when>
<xsl:when test="position() = 4 ">
<xsl:text>#96CCD8</xsl:text>
</xsl:when>
<xsl:when test="position() = 5 ">
<xsl:text>#19A347</xsl:text>
</xsl:when>
<xsl:when test="position() = 6 ">
<xsl:text>green</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>white</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="val"/>
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="./list">
<xsl:if test="position()!=1">
<fo:table-row>
<xsl:for-each select="./item">
<fo:table-cell border="4px" text-align="center">
<fo:block font-family="monospace" border-color="black"
border-style="solid" font-size="12pt" wrap-option="no-wrap"
padding="5pt" space-before="5pt" space-after="5pt">
<xsl:attribute name="background-color">
<xsl:choose>
<xsl:when test="position() = 1 ">
<xsl:text>#C1BFC4</xsl:text>
</xsl:when>
<xsl:when test="position() = 2 ">
<xsl:text>#B1A1C8</xsl:text>
</xsl:when>
<xsl:when test="position() = 3 ">
<xsl:text>#F9CAA0</xsl:text>
</xsl:when>
<xsl:when test="position() = 4 ">
<xsl:text>#96CCD8</xsl:text>
</xsl:when>
<xsl:when test="position() = 5 ">
<xsl:text>#C2D89A</xsl:text>
</xsl:when>
<xsl:when test="position() = 6 ">
<xsl:text>green</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>red</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="val"/>
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:if>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<records>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Subject Number</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Monthly Dairy Contact</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>3-Month Safety Contact</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Annual visit</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>Suspected HZ follow-up Visit</val>
</item>
</list>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>49210</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>x</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>15-sep-2012</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val></val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val></val>
</item>
</list>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>49210</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>x</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>15-sep-2012</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>test</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val></val>
</item>
</list>
<list>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>49210</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>x</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>15-sep-2012</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>test</val>
</item>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="jaXBValue">
<val>test</val>
</item>
</list>
</records>
最佳答案
对于水平居中,简短的回答是使用 text-align="center"
. (见 https://www.w3.org/TR/xsl11/#text-align)text-align
适用于fo:block
, fo:external-graphic
, fo:instream-foreign-object
, 和 fo:table-and-caption
.如果有需要居中的内联 FO,最简单的做法是将其包装在 fo:block
中。有 text-align="center"
.
水平居中 fo:table
的一种方法是把它放在 fo:table-and-caption
:
<fo:table-and-caption text-align="center">
<fo:table>
fo:inline-container
内
fo:block
:
<fo:block text-align="center">
<fo:inline-container>
<fo:table>
display-align="center"
. (见
https://www.w3.org/TR/xsl11/#display-align)
display-align
适用于
fo:region-body
,
fo:region-before
,
fo:region-after
,
fo:region-start
,
fo:region-end
,
fo:block-container
,
fo:external-graphic
,
fo:instream-foreign-object
,
fo:inline-container
, 和
fo:table-cell
.除此之外,这意味着您可以使垂直对齐成为页面母版设置的一部分,或者您可以仅居中
fo:table
把它放在全高
fo:block-container
:
<fo:block-container display-align="center" height="100%">
<fo:table-and-caption text-align="center">
<fo:table>
关于xslt - 如何在 xsl 中将文本和表格数据对齐到中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21023744/
我是一名优秀的程序员,十分优秀!