需要在PDF文件中显示两个不同的alt文本吗?

时间:2016-07-29 12:13:37

标签: xml xslt xsl-fo apache-fop

我正在通过XSL-FO模板解析XML数据,最后生成一个PDF文件来显示图像,以显示这些图像的两个不同的alt文本。根据XML文件上的标志,我选择一个alt文本在PDF上显示。

我的XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<list>
    <details>
        <name>Test123</name>
        <age>22</age>
        <isDuck>true</isDuck>
        <images>http://www.freedigitalphotos.net/images/img/homepage/87357.jpg</images>
    </details>
    <details>
        <name>Test123</name>
        <age>22</age>
        <isDog>true</isDog>
        <images>http://www.isharearena.com/wp-content/uploads/2012/12/wallpaper-281049.jpg?d54e04</images>
    </details>
    ...
</list>

我的XSL-FO:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="list">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" language="en"
            white-space-treatment="ignore-if-after-linefeed" role="Document" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="testing" page-width="21cm" page-height="29.7cm">
                    <fo:region-body margin-top="2cm" margin-bottom="2cm" 
                                    margin-left="2cm" margin-right="2cm"/>
                    <fo:region-after region-name="footer" extent="20mm"/>
                </fo:simple-page-master>
            </fo:layout-master-set>

            <fo:page-sequence master-reference="testing">
                <fo:flow flow-name="xsl-region-body">
                    <xsl:for-each select="./details">
                        <fo:block>
                            <xsl:choose>
                                <xsl:when test="isDuck = 'true'">
                                    <fo:external-graphic content-width="scale-to-fit" content-height="scale-to-fit" role="P" width="39.250em" height="23.250em" fox:alt-text="This is Duck">
                                        <xsl:attribute name="src">
                                            <xsl:value-of select="images" />
                                        </xsl:attribute>
                                    </fo:external-graphic>
                                </xsl:when>
                                <xsl:otherwise>
                                    <fo:external-graphic content-width="scale-to-fit" content-height="scale-to-fit" role="P" width="39.250em" height="23.250em" fox:alt-text="This is Dog">
                                        <xsl:attribute name="src">
                                            <xsl:value-of select="images" />
                                        </xsl:attribute>
                                    </fo:external-graphic>
                                </xsl:otherwise>
                            </xsl:choose>
                        </fo:block>
                    </xsl:for-each>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

我想将第一张图片的alt-text显示为&#34;这是Duck&#34; ,第二张图片显示为&#34;这是Dog&#34; < / strong>即可。我在PDF上获取图像,但fox:alt-text属性未在PDF文件中显示替代文本。

真的很感谢你对此的帮助......

0 个答案:

没有答案