使用XSL-FO,Apache FOP将元素右对齐

时间:2010-09-09 09:13:37

标签: xslt xsl-fo apache-fop

我正在使用XSL-FO和Apache FOP来获取性感的XML文件并将其输出为PDF,但是我有一个非常基本的问题,试图获取特定的信息(地址)从页面右侧开始,我可以通过增加left属性将其强制向右移动,但如果我更改页面大小,方向或边距,这将立即变得无用。

以下是XSL的代码,请注意第23行的注释。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="all-pages"
                        page-height="297mm"
                        page-width="210mm"
                        margin-top="1cm" 
                        margin-bottom="1cm"
                        margin-left="1cm" 
                        margin-right="1cm" >
                    <fo:region-body margin-top="5cm" margin-bottom="1.1cm"/>
                    <fo:region-before extent="1cm"/>
                    <fo:region-after extent="5mm"/>
                </fo:simple-page-master>
                <fo:page-sequence-master master-name="default-sequence">
                    <fo:repeatable-page-master-reference master-reference="all-pages"/>
                </fo:page-sequence-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="default-sequence">
                <fo:static-content flow-name="xsl-region-before" font-size="10pt" font-family="Helvetica" >
                    <!-- HERE'S MY PROBLEM, THE RIGHT ATTRIBUTE ISN'T BEHAVING ITSELF -->
                    <fo:block-container absolute-position="absolute" right="4cm" top="1cm" width="6cm"  border-style="solid" border-width="1mm"  >
                        <fo:list-block >
                            <fo:list-item>
                                <fo:list-item-label>
                                    <fo:block></fo:block>
                                </fo:list-item-label>
                                <fo:list-item-body>
                                    <fo:block>ABC</fo:block>
                                </fo:list-item-body>
                            </fo:list-item>
                            <fo:list-item>
                                <fo:list-item-label>
                                    <fo:block></fo:block>
                                </fo:list-item-label>
                                <fo:list-item-body>
                                    <fo:block>123</fo:block>
                                </fo:list-item-body>
                            </fo:list-item>
                        </fo:list-block>
                    </fo:block-container>
                </fo:static-content>
                <fo:static-content flow-name="xsl-region-after" padding-top="2pt" border-top-style="solid" border-top-width="1pt" border-top-color="rgb(192,192,192)" font-size="10pt" font-family="Helvetica">
                    <fo:block></fo:block>
                </fo:static-content>
                <fo:flow flow-name="xsl-region-body" font-size="10pt" font-family="Helvetica">
                    <fo:block></fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>


</xsl:stylesheet>

正如您在此屏幕截图中看到的那样,该元素未正确定位:

alt text

任何人都知道为什么会这样吗?

1 个答案:

答案 0 :(得分:3)

Bugger,查看FOP changelog和版本0.95和1.0之间的两年让我想到它是否是一个错误,下载了新的二进制文件,它现在从右边定位我的元素。