xslt-fo不支持utf-8吗?

use*_*705 8 xslt encoding xsl-fo apache-fop

我在utf-8中有一个带有编码属性的xml文件.

当我执行时fop -xml xml.xml -xsl xsl.xsl -pdf pdf.pdf,我的输出pdf已经破坏了utf-8字符.重要的是,xsl文件中的文本没有utf-8字符,与xml中的文本相同.

Utf-8字符被#替换.

可能有什么不对?

Xsl文件:

    <?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" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java" version="1.0" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" version="1.0" indent="yes" encoding="UTF-8" />

<xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

        <fo:layout-master-set>
          <fo:simple-page-master master-name="A4" margin="1cm">
            <fo:region-body  margin="2cm" margin-left="1cm" margin-right="1cm"/>
            <fo:region-before extent="3cm"/>
            <fo:region-after extent="5mm"/>
          </fo:simple-page-master>
        </fo:layout-master-set>

        <fo:page-sequence master-reference="A4">
            <fo:static-content flow-name="xsl-region-before">
                <fo:block font-size="24pt" font-family="Calibri">Filmoteka</fo:block>
            </fo:static-content>
            <fo:static-content flow-name="xsl-region-after">
                <fo:block font-size="10pt" font-family="Calibri">Wygenerowano: <xsl:call-template name="dataCzas" /></fo:block>
            </fo:static-content>

            <fo:flow flow-name="xsl-region-body">
                <fo:block font-size="12pt" font-family="Calibri" padding-after="1cm">
                    <fo:table table-layout="fixed" width="100%" border="solid black 1px">
                    <fo:table-column column-width="8mm"/>
                    <fo:table-column column-width="40mm"/>
                    <fo:table-column column-width="40mm"/>
                    <fo:table-column column-width="13mm"/>
                    <fo:table-column column-width="65mm"/>
                        <fo:table-header>
                            <fo:table-row>
                                <fo:table-cell border="solid black 2px">
                                    <fo:block font-weight="bold" background-color="#cccccc">Lp.</fo:block>
                                </fo:table-cell>
                                <fo:table-cell border="solid black 2px">
                                    <fo:block font-weight="bold" background-color="#cccccc">Tytu? PL</fo:block>
                                </fo:table-cell>
                                <fo:table-cell border="solid black 2px">
                                    <fo:block font-weight="bold" background-color="#cccccc">Re?yseria</fo:block>
                                </fo:table-cell>
                                <fo:table-cell border="solid black 2px">
                                    <fo:block font-weight="bold" background-color="#cccccc">Rok</fo:block>
                                </fo:table-cell>
                                <fo:table-cell border="solid black 2px">
                                    <fo:block font-weight="bold" background-color="#cccccc">Obsada</fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-header>
                        <fo:table-body>
                            <xsl:apply-templates />
                        </fo:table-body>
                    </fo:table>
                </fo:block>
            </fo:flow>



        </fo:page-sequence>

    </fo:root>
</xsl:template>


<xsl:template match="film">
    <fo:table-row>
        <fo:table-cell border="solid black 1px">
            <fo:block><xsl:number format="1"/></fo:block>
        </fo:table-cell>
        <fo:table-cell border="solid black 1px">
            <fo:block font-family="Calibri"><xsl:value-of select="tytul_pol"/></fo:block>
        </fo:table-cell>
        <fo:table-cell border="solid black 1px">
            <fo:block font-family="Calibri"><xsl:value-of select="rezyser"/></fo:block>
        </fo:table-cell>
        <fo:table-cell border="solid black 1px">
            <fo:block font-family="Calibri"><xsl:value-of select="rok"/></fo:block>
        </fo:table-cell>
        <fo:table-cell border="solid black 1px">
            <fo:block font-family="Calibri"><xsl:value-of select="obsada"/></fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

<xsl:template name="dataCzas">
    <xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('dd MMMM yyyy, HH:mm:ss'), java:java.util.Date.new())"/>
</xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

xml文件:

http://pastebin.com/fr9fChtn

Mat*_*ler 6

如果FOP输出字符#,则所选字体不包含表示它们的字形.

这可能是因为您的XML输入文件包含以下行:

<kraj>Francja, USA, W?ochy</kraj>
Run Code Online (Sandbox Code Playgroud)

这里有问题的角色是?.

所以,回答你的问题:FOP确实支持UTF-8,只是字体(在你的情况下font-family='Calibri':)没有表示字符的方法.

如果确实如此,FOP应该输出一个警告

WARNING: Glyph for "?" not available in font "DejaVuSans"
Run Code Online (Sandbox Code Playgroud)

现在,为了还要考虑那些不存在于您选择的字体中的字符,可以一起更改输出字体,或者作为变通方法,将它们与内联隔离.

例如,这是为了确保对于字符?(数学运算符),选择正确的字体:

<fo:block> 
    <fo:inline font-family='Symbol'>?</fo:inline>
</fo:block>
Run Code Online (Sandbox Code Playgroud)

有关FOP字体的更多信息,请参阅此页面:http://xmlgraphics.apache.org/fop/trunk/fonts.html.