【问题标题】:Apache FOP XSL/XSLT - Making text bold in generated PDFApache FOP XSL/XSLT - 在生成的 PDF 中使文本变为粗体
【发布时间】:2016-07-21 22:38:58
【问题描述】:

我有一个这样的 xml:

<?xml version="1.0" encoding="UTF-8"?>
<TermsAndConditions>
        <clause><clausetext>Terms and Conditions of Supply - Please read carefully</clausetext></clause>
        <clause><clausetext>Available only to <bold>customers who have an existing</bold> account.</clausetext></clause>
</TermsAndConditions>

样式表是:

<fo:page-sequence master-reference="simple" >
        <fo:flow flow-name="xsl-region-body">       
        <xsl:for-each select="data/TermsAndConditions/clause">
                <fo:block font-size="10pt" font-family="Arial" color="#6d6e71"><xsl:value-of select="clausetext" />
</fo:block>
                <fo:block font-size="10pt" font-family="Arial" line-height="10pt" space-after.optimum="3pt" text-align="justify">&#0160;</fo:block>
        </xsl:for-each>
    </fo:flow>
</fo:page-sequence>

如何在生成的pdf中将标签之间的文本设置为粗体?目前可以看到分句,但文字一切正常。

除此之外,我使用 w3schools.com 的 tryit 编辑器尝试了类似的事情: [http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=tryxsl_if]

使用以下样式表:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
     <xsl:apply-templates mode="tttt" />
  </body>
  </html>
</xsl:template>

  <xsl:template match="bold" mode="tttt">
     <b><xsl:value-of select="." /></b>
   </xsl:template>
</xsl:stylesheet>

我得到了想要的输出。

【问题讨论】:

  • 您显示的样式表会生成 hrml。您至少需要使用 XSL FO for Apache FOP
  • 我正在使用 xsl fo。第二个样式表基于第一个样式表,只是作为概念证明。

标签: xml apache xslt apache-fop


【解决方案1】:

&lt;b&gt; 是 html 语法,因为这可能应该是:

<xsl:template match="bold" mode="tttt">
     <fo:inline font-weight="bold"><xsl:value-of select="." /></fo:inline>
   </xsl:template>
</xsl:stylesheet>

【讨论】:

  • @user2260040,你没有接受很多答案,这是在 SO 上说“谢谢”的方式 - 这个答案对你有帮助吗,或者我们能做些什么来帮助你?
猜你喜欢
  • 2019-08-26
  • 2013-06-15
  • 1970-01-01
  • 1970-01-01
  • 2022-11-25
  • 2020-04-06
  • 1970-01-01
  • 2012-10-25
  • 1970-01-01
相关资源
最近更新 更多