使用XSLT以11 * 17(横向)生成PDF

时间:2015-12-22 03:17:35

标签: pdf xslt xslt-1.0 xsl-fo

我有这个要求,我需要使用XSLT以11 * 17大小和横向格式创建PDS。我可以使用XSl FO以A4页面大小创建PDF。

我的XSLT如下:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family = "Helvetica" font-size = "10px">
            <fo:layout-master-set>
                <fo:simple-page-master margin-bottom="0.5cm" margin-left="0.75cm" margin-right="0.75cm" margin-top="0.5cm" master-name="first" page-height="27.9cm" page-width="21.6cm">
                    <fo:region-body margin-bottom = "0.5cm" margin-top = "0.25cm"/>
                    <fo:region-before extent = "0cm"/>
                    <fo:region-after extent = "0.5cm"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <xsl:for-each select="Rowsets">
                <fo:page-sequence master-reference="first">
                    <fo:static-content flow-name="xsl-region-after">
                        <fo:block font-size="8pt" line-height="6pt" text-align-last="justify">
                            Shift Report
                            <fo:inline id="Date">
                                Date [currentDate]
                            </fo:inline>
                            <fo:leader leader-pattern = "space"/>
                            Page
                            <fo:page-number/>
                        </fo:block>                 
                    </fo:static-content>
                    <fo:flow flow-name="xsl-region-body">
                        <xsl:for-each select="Rowset">
                            <xsl:choose>
                                <xsl:when test="Columns/Column[1]/@Description = 'Break'">
                                    <fo:block page-break-before="always" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <fo:table border-color="black" border-style="solid" border-width="1pt" table-layout="fixed" width="100%">
                                        <xsl:variable name="columns">
                                            <xsl:value-of select="count(Columns/Column)" />
                                        </xsl:variable>
                                        <xsl:for-each select="Columns/Column">
                                            <xsl:choose>
                                                <xsl:when test="position()&lt;2">
                                                    <fo:table-column column-width="62pt" />
                                                </xsl:when>
                                                <xsl:when test="position()&gt;1 and position()&lt;4">
                                                    <fo:table-column column-width="40pt" />
                                                </xsl:when>
                                                <xsl:when test="position()&gt;4 and position()&lt;6">
                                                    <fo:table-column column-width="40pt" />
                                                </xsl:when>
                                                <xsl:when test="position()&gt;8">
                                                    <fo:table-column column-width="60pt" />
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <fo:table-column />
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:for-each>
                                        <fo:table-body font-size="10pt">
                                            <fo:table-row height="13pt">
                                                <fo:table-cell background-color="#000000" border-style="solid" border-width="1pt" padding-left="5pt" padding-top="5pt" number-columns-spanned="{$columns}">
                                                    <fo:block font-weight="bold" text-align="center" color="#FFFFFF">
                                                        Shift Report
                                                    </fo:block>
                                                </fo:table-cell>
                                            </fo:table-row>
                                                <fo:table-row height="13pt">
                                                    <xsl:for-each select="Columns/Column">
                                                        <fo:table-cell background-color="#CCCCCC" border-style="solid" border-width="1pt" padding-left="5pt" padding-top="5pt">
                                                            <fo:block font-weight="bold" text-align="left">
                                                                <xsl:value-of select="translate(@Name,'_',' ')" />
                                                            </fo:block>
                                                        </fo:table-cell>
                                                    </xsl:for-each>
                                                </fo:table-row>
                                            <xsl:for-each select="Row">
                                                <fo:table-row height="13pt">
                                                    <xsl:for-each select="child::*">
                                                        <fo:table-cell background-color="#FFFFFF" border-style="solid" border-width="1pt" padding-left="5pt" padding-top="5pt">
                                                            <fo:block font-weight="normal" text-align="left">
                                                                <xsl:value-of select="." />
                                                            </fo:block>
                                                        </fo:table-cell>
                                                    </xsl:for-each>
                                                </fo:table-row>
                                            </xsl:for-each>
                                        </fo:table-body>
                                    </fo:table>
                                    <fo:block text-indent="2pc" space-after="7pt" space-before.minimum="6pt" space-before.optimum="8pt" space-before.maximum="10pt">
                                    </fo:block>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:for-each>
                    </fo:flow>
                </fo:page-sequence>
            </xsl:for-each>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

我不确定在哪里可以进行更改以适应11 * 17尺寸和横向。

此外,列(标题)名称之一是“QualityPercent”。我想将其更改为“质量%”

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

  • page-height="27.9cm" page-width="21.6cm"更改为page-height="11in" page-width="17in"

编辑:

变化:

<xsl:value-of select="translate(@Name,'_',' ')" />

<xsl:choose>
  <xsl:when test="contains(@Name, 'Percent')">
    <xsl:value-of select="substring-before(@Name, 'Percent')" />
    <xsl:text>%</xsl:text>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="translate(@Name,'_',' ')" />
  </xsl:otherwise>
</xsl:choose>

如果您使用的是XSLT 2.0(或3.0),则可以使用replace()更轻松,准确地将Percent替换为任何%值中的@Name