XSLT-ApacheFOP-PDF中的粗体和斜体标记



我曾经使用Apache FOP与XML和XSL文件、生成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 Fiddlehttps://xsltfiddle.liberty-development.net/gVhDDyJ

请张贴解决方案。提前谢谢。

只有当您使用apply-templates而不是value-of时,才会使用bi的模板,因此请更改

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

https://xsltfiddle.liberty-development.net/gVhDDyJ/2

如果您仍然有问题,请告诉我们您想要的确切输出。

相关内容

  • 没有找到相关文章

最新更新