简体   繁体   English

如何使用xsl-fo防止文字在区域的前后移动?

[英]How can I prevent text from going over the before and after regions using xsl-fo?

I'm loading allot of text into a PDF using xsl-fo. 我正在使用xsl-fo将文本分配到PDF中。 But when it loads it fills the page entirely from border to border. 但是,当它加载时,整个页面会从一个边框到另一个边框完全填充。 Is there a way to prevent the text from being able to go over the before, after, start and end blocks, or should I just put margins on the blocks containing my text? 有没有一种方法可以防止文本能够越过之前,之后,开始和结束块,还是应该在包含文本的块上加上边距?

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

That is the code to display the Pros, Cons and Review content of the xml file. 那是显示xml文件的优点,缺点和审阅内容的代码。 It displays all the information and pictures correctly and inserts a page break after the Cons as it must. 它会正确显示所有信息和图片,并在“缺点”后面插入分页符。 But the problem comes in where the Review content is too much for just one page and displays over the after- and before-regions. 但是问题出在其中“评论”内容对于一页来说太多了,并且显示在前后区域中。

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

Here is the regions and their names: 这是地区及其名称:

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

(PS the body stretches to the page border and not just to the other regions) (PS正文会延伸到页面边框,而不仅仅是其他区域)

It seems you missed two things here: 看来您在这里错过了两件事:

First, width and height of page, change <fo:simple-page-master master-name="forSalePage"> with <fo:simple-page-master master-name="forSalePage" page-height="11in" page-width="8.5in"> 首先,页面的宽度和高度,将<fo:simple-page-master master-name="forSalePage"><fo:simple-page-master master-name="forSalePage" page-height="11in" page-width="8.5in">

Second, change <fo:region-body/> with <fo:region-body margin="1in"/> 其次,将<fo:region-body/>更改为<fo:region-body margin="1in"/>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM