如何将段落中的某些文本转换为粗体 xsl fo?

How to convert some text in paragraph into bold xsl fo?

这是我的 xml 的样子:

xml:

<Documents>
 <Document>
<Note>
  <Header>
    <HeaderText> &lt;b&gt;Need Help?&lt;/b&gt; Contact Our Customer Happiness Team
     by phone  &lt;b&gt;0345 00002662&lt;/b&gt;
     Mon-Fri 9am-7pm
   </HeaderText>
  </Header>
  </Note>
 </Document>
   </Documents>

我想将 HeaderText 中的一些文本转换为粗体。例如 需要帮助? 联系我们的客户满意度团队 通过 phone 0345 00002662 周一至周五上午 9 点至晚上 7 点

Xslt:

 <fo:table-header text-align="left" border-width="0mm">
    <fo:table-row margin-left="1cm" font-family="Avenir" font-size="14pt">
      <fo:table-cell>
        <fo:block padding-top="0cm">
          <xsl:value-of select="HeaderText" />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-header>
 

检查此代码:-

 <fo:table-header text-align="left" border-width="0mm">
     <fo:table-row margin-left="1cm" font-family="Avenir" font-size="14pt">
      <fo:table-cell>
        <fo:block padding-top="0cm">
          <xsl:apply-templates/>
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-header>

<xsl:template match="bold">
    <fo:inline font-weight="bold">
        <xsl:apply-templates/>
    </fo:inline>
</xsl:template>

&lt;b&gt;Need Help?&lt;/b&gt; 只是 XSLT 处理器和 XSL-FO 格式化程序的文本。

这类似于XSLT - How to treat inline/escaped XML within a node as nested nodes。那里的建议只是分两次完成或使用 XSLT 2.0 或 3.0。

如果 &lt;b&gt; 是您唯一需要转换为真实标记的 non-element,那么您可以使用递归模板来完成:

<xsl:template match="text()[contains(., '&lt;b>')]"
              name="unescape-bold">
  <xsl:param name="text" select="." />

  <xsl:choose>
    <xsl:when test="not(contains($text, '&lt;b>'))">
      <xsl:value-of select="$text" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="substring-before($text, '&lt;b>')" />
      <fo:inline font-weight="bold">
        <xsl:value-of
            select="substring-before(substring-after($text, '&lt;b>'),
                                     '&lt;/b>')" />
      </fo:inline>
      <xsl:call-template name="unescape-bold">
        <xsl:with-param name="text"
                        select="substring-after($text, '&lt;/b>')" />
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

对于您的样本,这给出了:

 <fo:inline font-weight="bold">Need Help?</fo:inline> Contact Our Customer Happiness Team
     by phone  <fo:inline font-weight="bold">0345 00002662</fo:inline>
     Mon-Fri 9am-7pm