有什么方法可以运行XSLT并使用Apache fop在线生成PDF?

问题描述 投票:0回答:1

我想在线生成PDF,例如xslt tranformation

INPUT XML:

<?xml version="1.0" encoding="UTF-8"?>
<students>
    <student>
        <name>Amrendra Kumar</name>
        <class>BCA</class>
    </student>
    <student>
        <name>Sanjeev Kumar</name>
        <class>MCA</class>
    </student>
</students>

XSLT以生成PDF:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    exclude-result-prefixes="xs"
    version="2.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="a">
                    <fo:region-body margin="1in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="a">
                <fo:flow flow-name="xsl-region-body">
                    <fo:block>
                        <fo:table border="1pt">
                            <fo:table-column column-number="1" column-width="180pt"/>
                            <fo:table-column column-number="2" column-width="300pt"/>
                            <fo:table-header>
                                <fo:table-row padding-top="0pt" padding-bottom="0pt">
                                    <fo:table-cell>
                                        <fo:block font-family="TimesNewRoman" font-size="10pt"  space-before="4pt" text-align="left">
                                            <fo:inline font-weight="bold" font-size="12pt">Name</fo:inline>
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block font-family="TimesNewRoman" font-size="10pt"  space-before="4pt" text-align="left">
                                            <fo:inline font-weight="bold" font-size="12pt">Class</fo:inline>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </fo:table-header>
                            <fo:table-body start-indent="0pt" end-indent="0pt">
                                <xsl:for-each select="students/student">
                                    <fo:table-row padding-top="0pt" padding-bottom="0pt">
                                        <fo:table-cell>
                                            <fo:block font-family="TimesNewRoman" font-size="10pt"  space-before="4pt" text-align="left">
                                                <fo:inline font-size="12pt">
                                                    <xsl:value-of select="name"/>
                                                </fo:inline>
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell>
                                            <fo:block font-family="TimesNewRoman" font-size="10pt"  space-before="4pt" text-align="left">
                                                <fo:inline font-size="12pt">
                                                    <xsl:value-of select="class"/>
                                                </fo:inline>
                                            </fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>
                                </xsl:for-each>
                            </fo:table-body>
                        </fo:table>
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>


</xsl:stylesheet>

[输出:需要在线生成PDF

xml xslt pdf-generation xslt-2.0 xsl-fo
1个回答
0
投票

我认为这应该是您要寻找的:http://www.utilities-online.info/foprender/#.XeaIvegzaUk

注意,此页面中使用的库是Apache FOP 1.0。

© www.soinside.com 2019 - 2024. All rights reserved.