gpt4 book ai didi

xslt - 如何使用 xsl-fo 翻译数据中的 标签

转载 作者:行者123 更新时间:2023-12-04 06:07:44 26 4
gpt4 key购买 nike

我报告说我必须使用 xsl-fo 从来自 MySQL 数据库的 xml 数据转换为 PDF。

我正在处理的 xml 结构已经用于创建 HTML 报告。

通过将 disable-output-escaping="yes"添加到我的 xsl:value-of 语句,我可以在 HTML 报告中使用某些已经包含 html 标记的字段。

我如何在 xsl-fo 中做类似的操作?有没有办法可以将标签更改为 fo:inline?或者也许我可以在数据库输出中更改某些内容,这将是等效的 PDF 版本的粗体?

这是一个xml片段:

<foal_line>
<yob>0</yob>
<description>Tis The Alarm. Unplaced at 3 in NA. Dam of <B>SA MOKEN</B> (f, by Smoke Glacken. 2 wins at 2, $60,382 in NA. Won Ken Kendrick Memorial Futurity (SRP, $25,043). 2nd Kachina S. (RUI, $10,982). 3rd Ruidoso Thoroughbred Futurity (RUI, $7,787), etc.) Granddam of <B>Dream Kin</B> (f, by Desert God. 4 wins, 2 to 4, $127,880 in US. 2nd New Mexico Cup Juv. Fillies S.-R (ZIA, $33,440). 3rd C. O. "Ken" Kendrick Memorial S-R (SRP, $7,500), Lincoln H. [R] (RUI, $5,000), Carlos Salazar S. [N] (ALB, $4,000), etc.)</description>
</foal_line>

我之前创建 xhtml 的 xslt 片段:
<tr>
<td width="30px" style="vertical-align:text-top;">
<xsl:value-of select="yob"/>
</td>
<td style="vertical-align:text-top;text-align:left;padding-left:2px">
<xsl:value-of select="description" disable-output-escaping="yes" />
</td>
</tr>

我当前的 xsl-fo 片段:
<fo:table-row>
<fo:table-cell>
<fo:block><xsl:value-of select="yob"/></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block><xsl:value-of select="description"/></fo:block>
</fo:table-cell>
</fo:table-row>

编辑:
这是我从服务器真正得到的。这就是我使用 IE 查看我的 xml 所得到的。
<foal_line>
<yob>0</yob>
<description>Tis The Alarm. Unplaced at 3 in NA. Dam of &lt;B&gt;SA MOKEN&lt;/B&gt; (f, by Smoke Glacken. 2 wins at 2, $60,382 in NA. Won Ken Kendrick Memorial Futurity (SRP, $25,043). 2nd Kachina S. (RUI, $10,982). 3rd Ruidoso Thoroughbred Futurity (RUI, $7,787), etc.) Granddam of &lt;B&gt;Dream Kin&lt;/B&gt; (f, by Desert God. 4 wins, 2 to 4, $127,880 in US. 2nd New Mexico Cup Juv. Fillies S.-R (ZIA, $33,440). 3rd C. O. "Ken" Kendrick Memorial S-R (SRP, $7,500), Lincoln H. [R] (RUI, $5,000), Carlos Salazar S. [N] (ALB, $4,000), etc.)</description>
</foal_line>

这就是为什么建议的答案不起作用。

最佳答案

而不是做 xsl:value-of<description> , 做 xsl:apply-templates .然后您可以创建一个模板来匹配 <B> .在 B您可以使用的模板 fo:inline使文本加粗。

下面是一个例子:

  <xsl:template match="foal_line">
<fo:table-row>
<fo:table-cell>
<fo:block><xsl:value-of select="yob"/></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block><xsl:apply-templates select="description"/></fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

<xsl:template match="description">
<xsl:apply-templates/>
</xsl:template>

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

使用您的 XML 输入和上述模板,将生成以下输出:
<fo:table-row xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:table-cell>
<fo:block>0</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Tis The Alarm. Unplaced at 3 in NA. Dam of <fo:inline font-weight="bold">SA MOKEN</fo:inline> (f, by Smoke Glacken. 2 wins at 2, $60,382 in NA. Won Ken Kendrick Memorial Futurity (SRP, $25,043). 2nd Kachina S. (RUI, $10,982). 3rd Ruidoso Thoroughbred Futurity (RUI, $7,787), etc.) Granddam of <fo:inline font-weight="bold">Dream Kin</fo:inline> (f, by Desert God. 4 wins, 2 to 4, $127,880 in US. 2nd New Mexico Cup Juv. Fillies S.-R (ZIA, $33,440). 3rd C. O. "Ken" Kendrick Memorial S-R (SRP, $7,500), Lincoln H. [R] (RUI, $5,000), Carlos Salazar S. [N] (ALB, $4,000), etc.)</fo:block>
</fo:table-cell>
</fo:table-row>

另外,你应该对 <yob> 做同样的事情。如果它也是混合内容(文本和其他元素,例如 <B> )。

您也可以为 XHTML XSLT 执行此操作,因此您不必使用 disable-output-escaping (我会不惜一切代价避免这种情况)。

关于xslt - 如何使用 xsl-fo 翻译数据中的 <b> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8156611/

26 4 0