如何使用xsl-fo阻止文本覆盖前后区域?

时间:2013-05-21 06:39:52

标签: xml xslt pdf xsl-fo regions

我正在使用xsl-fo将分配文本加载到PDF中。但是当它加载时,它完全从边界到边界填充页面。有没有办法阻止文本覆盖前,后,开始和结束块,或者我应该只将边距放在包含我的文本的块上?

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
    <fo:root>
        <!-- overall layout -->
        <fo:layout-master-set>
            <fo:simple-page-master master-name="forSalePage">
                <fo:region-body/>
                <fo:region-before   extent="1in" background-color="#0000FF" />
                <fo:region-after    extent="1in" background-color="#0000FF" />
                <fo:region-start/>
                <fo:region-end/>
            </fo:simple-page-master>
        </fo:layout-master-set>

        <!-- page content -->
        <xsl:for-each select="ovgs/forSale/game">
            <fo:page-sequence master-reference="forSalePage">
                <fo:flow flow-name="xsl-region-body">
                    <fo:block text-align="center" margin-top="0.1in">Pros:</fo:block>
                    <xsl:for-each select="review/pros/pro">
                        <fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
                    </xsl:for-each>
                    <fo:block text-align="center" margin-top="0.1in">Cons:</fo:block>
                    <xsl:for-each select="review/cons/con">
                        <fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
                    </xsl:for-each>
                    <fo:block page-break-before="always" margin-top="1.1in" margin-right="1in" margin-left="1in">Content:</fo:block>
                    <xsl:for-each select="review/content/*">
                        <xsl:choose>
                            <xsl:when test=". = not(node())">
                                <fo:block margin-top="0.1in" margin-right="1in" margin-left="1in"><xsl:value-of select="./preceding::text()[1]" /></fo:block>
                            </xsl:when>
                            <xsl:when test=". = text()">
                                <fo:block text-align="center" margin-top="0.1in"><fo:external-graphic content-height="scale-to-fit" height="1in"><xsl:attribute name="src">url('<xsl:value-of select="./@url" />')</xsl:attribute></fo:external-graphic></fo:block>
                                <fo:block text-align="center" margin-right="1in" margin-left="1in"><xsl:value-of select="." /></fo:block>
                            </xsl:when>
                            <xsl:otherwise/>
                        </xsl:choose>
                    </xsl:for-each>
                    <fo:block margin-right="1in" margin-left="1in" margin-top="0.1in"><xsl:value-of select="review/content/p[last()]/following::text()[1]" /></fo:block>
                </fo:flow>
            </fo:page-sequence>
        </xsl:for-each>
    </fo:root>
</xsl:template>

这是显示xml文件的优缺点,缺点和评论内容的代码。它正确显示所有信息和图片,并在Cons之后插入分页符。但问题在于,评论内容对于一个页面而言太多,并且显示在之后和之前的区域。

What I get:           What I want:
 ______________       ______________
|              |     |              |
|  Pros        |     |  Pros        |
|    Blabla    |     |    Blabla    |
|              |     |              |
|  Cons        |     |  Cons        |
|    Blabla    |     |    Blabla    |
|              |     |              |
|              |     |              |
|______________|     |______________|
 ______________       ______________
|              |     |              |
|  Content     |     |  Content     |
|              |     |              |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|__~~~~~~~~~~__|     |______________|
 ______________       ______________
|  ~~~~~~~~~~  |     |              |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|              |     |  ~~~~~~~~~~  |
|              |     |  ~~~~~~~~~~  |
|              |     |              |
|              |     |              |
|______________|     |______________|

以下是地区及其名称:

 ______________
|    Before    |
|______________|
| S|        |  |
| t|        |E |
| a|  Body  |n |
| r|        |d |
| t|        |  |
|__|________|__|
|    After     |
|______________|

(P.S。身体伸展到页面边框而不仅仅是其他区域)

2 个答案:

答案 0 :(得分:4)

看来你错过了两件事:

首先,页面的宽度和高度,使用<fo:simple-page-master master-name="forSalePage">

更改<fo:simple-page-master master-name="forSalePage" page-height="11in" page-width="8.5in">

其次,使用<fo:region-body/>

更改<fo:region-body margin="1in"/>

答案 1 :(得分:1)

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
    <fo:root>
        <!-- overall layout -->
        <fo:layout-master-set>
            <fo:simple-page-master master-name="forSalePage">
                <fo:region-body margin="1in" />
                <fo:region-before   extent="1in" background-color="#0000FF" />
                <fo:region-after    extent="1in" background-color="#0000FF" />
                <fo:region-start/>
                <fo:region-end/>
            </fo:simple-page-master>
        </fo:layout-master-set>

        <!-- page content -->
        <xsl:for-each select="ovgs/forSale/game">
            <fo:page-sequence master-reference="forSalePage">
                <fo:flow flow-name="xsl-region-body">
                    <fo:block text-align="center" margin-top="0.1in">Pros:</fo:block>
                    <xsl:for-each select="review/pros/pro">
                        <fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
                    </xsl:for-each>
                    <fo:block text-align="center" margin-top="0.1in">Cons:</fo:block>
                    <xsl:for-each select="review/cons/con">
                        <fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
                    </xsl:for-each>
                    <fo:block page-break-before="always" margin-top="0.1in">Content:</fo:block>
                    <xsl:for-each select="review/content/*">
                        <xsl:choose>
                            <xsl:when test=". = not(node())">
                                <fo:block margin-top="0.1in"><xsl:value-of select="./preceding::text()[1]" /></fo:block>
                            </xsl:when>
                            <xsl:when test=". = text()">
                                <fo:block text-align="center" margin-top="0.1in"><fo:external-graphic content-height="scale-to-fit" height="1in"><xsl:attribute name="src">url('<xsl:value-of select="./@url" />')</xsl:attribute></fo:external-graphic></fo:block>
                                <fo:block text-align="center"><xsl:value-of select="." /></fo:block>
                            </xsl:when>
                            <xsl:otherwise/>
                        </xsl:choose>
                    </xsl:for-each>
                    <fo:block margin-top="0.1in"><xsl:value-of select="review/content/p[last()]/following::text()[1]" /></fo:block>
                </fo:flow>
            </fo:page-sequence>
        </xsl:for-each>
    </fo:root>
</xsl:template>