Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 如何翻译<;b>;使用xsl-fo标记数据内部_Xslt_Xsl Fo - Fatal编程技术网

Xslt 如何翻译<;b>;使用xsl-fo标记数据内部

Xslt 如何翻译<;b>;使用xsl-fo标记数据内部,xslt,xsl-fo,Xslt,Xsl Fo,我有一个报告,我必须使用xsl fo将来自MySQL数据库的xml数据转换为PDF 我正在使用的xml结构已经用于创建HTML报告 某些字段中已经有html标记,我可以通过在xsl:value of的语句中添加disable-output-escaping=“yes”来在html报告中使用这些标记 如何在xsl fo中执行类似的操作?有没有办法将标记更改为fo:inline?或者我可以在数据库输出中更改一些内容,这些内容将相当于粗体的PDF版本 以下是一个xml片段: <foal_line

我有一个报告,我必须使用xsl fo将来自MySQL数据库的xml数据转换为PDF

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

某些字段中已经有html标记,我可以通过在xsl:value of的语句中添加disable-output-escaping=“yes”来在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>

0
这是闹钟。在北卡罗来纳州3号位置未定位。萨莫肯大坝(f,由Smoke Glacken设计。2胜2负,北美60382美元。赢得肯·肯德里克纪念未来(SRP,25043美元)。第二卡奇纳S(RUI,10982美元)。第三鲁多索纯种未来(Ruidoso纯种未来(RUI,7787美元)等)。梦之亲大坝(f,由沙漠之神设计。4胜,2比4,美国127880美元。第二届新墨西哥杯Juv.小母马S.-R(ZIA,33440美元)。第三届C.O.“肯”肯德里克纪念馆S-R(SRP,7500美元)、林肯H.[R](鲁伊,5000美元)、卡洛斯·萨拉扎S.[N](ALB,4000美元)等)
我以前创建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>

0
这是闹钟。在北卡罗来纳州3号位置未定位。BSA MOKEN/B的大坝(f,由Smoke Glacken设计,2胜2负,在NA为60382美元。赢得Ken Kendrick Memorial Futurity(SRP,25043美元)。第二个Kachina S(RUI,10982美元)。第三个Ruidoso纯种Futurity(RUI,7787美元),等等)B梦想之亲的大坝(f,由沙漠之神设计,4胜,2比4,在美国为127880美元。第二届新墨西哥杯Juv.小母马S-R(ZIA,33440美元)。第三届C.O.“Ken”肯德里克纪念馆S-R(SRP,7500美元)、林肯H.[R](鲁伊,5000美元)、卡洛斯·萨拉扎S.[N](ALB,4000美元)等)

这就是建议答案不起作用的原因。

对于
,不要执行
xsl:value of
,而是执行
xsl:apply templates
。然后,您可以创建一个模板来匹配
。在
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>

0
这是闹钟。在北卡罗来纳州3号位置未定位。萨莫肯大坝(f,由Smoke Glacken设计。2胜2负,北美60382美元。赢得肯·肯德里克纪念未来(SRP,25043美元)。第二卡奇纳S(RUI,10982美元)。第三鲁多索纯种未来(Ruidoso纯种未来(RUI,7787美元)等)。梦之亲大坝(f,由沙漠之神设计。4胜,2比4,美国127880美元。第二届新墨西哥杯Juv.小母马S.-R(ZIA,33440美元)。第三届C.O.“肯”肯德里克纪念馆S-R(SRP,7500美元)、林肯H.[R](鲁伊,5000美元)、卡洛斯·萨拉扎S.[N](ALB,4000美元)等)
此外,如果
也是混合内容(文本和其他元素,如
),您也应该对其执行相同的操作


您也可以对XHTML XSLT执行此操作,这样就不必使用
禁用输出转义
(我会不惜一切代价避免这种情况)。

我知道这个问题已经很老了。我使用的是ApacheFop,并被这种编码或原始HTML处理的行为所困扰。这是我的解决方案,我已经研究了几个小时了

XML:


0
HTML文本可以是粗体和斜体
XSL:


页脚
标题
Yob:
描述:
描述
大胆的
斜体

最后,我得到了一个格式良好的FO,可以将其转换为PDF。

这对我来说不太合适。使用XSLT调试器,我可以看到它将进入模板match=“description”,但它与“B”的模板不匹配。谢谢你的帮助。我想我找到了我的问题。原始xml实际上正在执行转义括号。B和/B如果我手动将其编辑为适当的粗体标记,它就会工作。在完成完整的循环后,我已经能够使DevNull的解决方案工作。我必须将我的文档对象转换为字符串,并用相应的非转义字符替换and,然后重新解析为文档对象,以将粗体标记识别为节点。然后样式表能够用适当的FOP粗体字替换。谢谢
    <foal_line>
        <yob>0</yob> 
        <description><html xmlns="http://www.w3.org/1999/xhtml">HTML text can be <b>bold</b> and <i>italic</i></html></description>
    </foal_line>
<xsl:stylesheet version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xhtml="http://www.w3.org/1999/xhtml"
 >

    <!--  Output in XML -->
    <xsl:output method="xml" version="1.0" indent="yes" />

    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <!-- Templates                                                          -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    <xsl:template match="/">    
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="seite" page-width="210mm" page-height="297mm" margin="20mm 20mm 20mm 20mm">
                    <fo:region-body margin="20mm 0mm 10mm 0mm"/>
                    <fo:region-before region-name="header"/>
                    <fo:region-after region-name="footer"/>
                </fo:simple-page-master>
            </fo:layout-master-set>

            <fo:page-sequence id="seite" master-reference="seite">
                <fo:static-content flow-name="footer">
                    <fo:block>Footer</fo:block>
                </fo:static-content>
                <fo:static-content flow-name="header">
                    <fo:block>Header</fo:block>
                </fo:static-content>
                <fo:flow flow-name="xsl-region-body">
                    <xsl:apply-templates/>
                </fo:flow>
            </fo:page-sequence>         
        </fo:root>
    </xsl:template>

    <xsl:template match="foal_line">
        <fo:block-container>
            <fo:block>Yob: <xsl:value-of select="yob"/></fo:block>
            <fo:block>Desc: 
                <xsl:apply-templates select="description/xhtml:html"/>
            </fo:block>         
        </fo:block-container>
    </xsl:template>

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

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

    <xsl:template match="xhtml:i">
        <xsl:message>italic</xsl:message>
        <fo:inline font-style="italic"><xsl:apply-templates/></fo:inline>
    </xsl:template>
</xsl:stylesheet>