XSLT中的粗体和斜体标签-Apache FOP-PDF

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

我曾经使用带有XML和XSL文件的Apache FOP生成PDF,

XML

<?xml version="1.0" encoding="UTF-8"?>
<ReportMain>
    <ReportMainBody>
        <company>
             some <b>company</b>
        </company>
        <currency>
            some <i>other <b>currency</b></i>
        </currency>
    </ReportMainBody>
</ReportMain>

XSL

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <xsl:template match="ReportMain">
            <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
                <fo:layout-master-set>
                    <fo:simple-page-master master-name="simple"
                        page-height="8.5in" page-width="11in" margin-top=".5in"
                        margin-bottom=".5in" margin-left=".5in" margin-right=".5in">
                        <fo:region-body margin-top="2cm" margin-bottom="2cm" />
                        <fo:region-before extent="2cm" overflow="hidden" />
                        <fo:region-after extent="1cm" overflow="hidden" />
                    </fo:simple-page-master>
                </fo:layout-master-set>
                <fo:page-sequence master-reference="simple"
                    initial-page-number="1">
                    <fo:static-content flow-name="xsl-region-before">
                        <fo:block font-size="13.0pt" font-family="serif"
                            padding-after="2.0pt" space-before="4.0pt" text-align="center"
                            border-bottom-style="solid" border-bottom-width="1.0pt">
                            <fo:block>SAMPLE PDF</fo:block>
                        </fo:block>
                    </fo:static-content>
                    <fo:static-content flow-name="xsl-region-after">
                        <fo:block font-size="12.0pt" font-family="sans-serif"
                            padding-after="2.0pt" space-before="2.0pt" text-align="center"
                            border-top-style="solid" border-bottom-width="1.0pt">
                            <xsl:text>Page</xsl:text>
                            <fo:page-number />
                        </fo:block>
                    </fo:static-content>
                    <fo:flow flow-name="xsl-region-body">
                        <xsl:apply-templates select="ReportMainBody" />
                    </fo:flow>
                </fo:page-sequence>
            </fo:root>
        </xsl:template>

        <xsl:template match="ReportMainBody">
            <fo:block font-size="16pt" space-after="5mm">
                <xsl:value-of select="company"/>
            </fo:block>
            <fo:block font-size="16pt" space-after="5mm">
                <xsl:value-of select="currency"/>
            </fo:block>
        </xsl:template>

    <xsl:template match="b">
        <fo:inline font-weight="bold">
            <xsl:apply-templates select="node()"/>
        </fo:inline>  
    </xsl:template>

    <xsl:template match="i">
        <fo:inline font-style="italic">
            <xsl:apply-templates select="node()"/>
        </fo:inline>
    </xsl:template>
 </xsl:stylesheet>

我需要在我的PDF中使用粗体和斜体文本,实际上我从堆栈中的类似问题尝试了此解决方案,

请检查我的XSLT小提琴https://xsltfiddle.liberty-development.net/gVhDDyJ

请发布解决方案。预先感谢。

xml xslt-1.0 xslt-2.0 apache-fop
1个回答
1
投票
如果您仍有问题,请告诉我们您想要的输出。
© www.soinside.com 2019 - 2024. All rights reserved.