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



我有这个需求,我需要用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"。我想把它改成"质量%"

有人能帮忙吗?

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

还有size的简写(请参阅https://www.w3.org/TR/xsl11/#size)。如果支持,您可以使用size="17in 11in"。一些格式化程序(包括AH格式化程序:https://www.antenna.co.jp/AHF/help/en/ahf-ext.html#axf.size)识别纸张大小的一些关键字集,这样您也可以使用size="Ledger"


编辑:

更改:

<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>

如果您使用的是XSLT2.0(或3.0),则可以使用replace()在任何@Name值中更容易、更准确地将Percent替换为%

相关内容

  • 没有找到相关文章

最新更新