我正在使用xsl-fo将文本分配加载到pdf中。但当它加载时,它会完全从一个边框填充到另一个边框。有什么方法可以防止文本遍历before、after、start和end块,还是应该在包含文本的块上加边距?

<?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.正文延伸到页面边框,而不仅仅是其他区域)

最佳答案

你好像错过了两件事:
首先,页面的宽度和高度,将<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"/>

关于xml - 如何使用xsl-fo防止文字在区域的前后移动?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16663661/

10-13 05:50