XSLT 中的粗体和斜体标记 - Apache FOP - PDF
Bold and Italic Tags in XSLT - Apache FOP - 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 Fiddle https://xsltfiddle.liberty-development.net/gVhDDyJ
请post解决。提前致谢。
只有当您使用 apply-templates
而不是 value-of
时,您的 b
或 i
模板才会被使用,因此更改
<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
如果您仍然遇到问题,请准确告诉我们您想要的输出。
我曾经使用 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 Fiddle https://xsltfiddle.liberty-development.net/gVhDDyJ
请post解决。提前致谢。
只有当您使用 apply-templates
而不是 value-of
时,您的 b
或 i
模板才会被使用,因此更改
<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
如果您仍然遇到问题,请准确告诉我们您想要的输出。