简体   繁体   English

通过XSLT将XML节点中的HTML转义为XSL-FO

[英]Escaped HTML in XML node via XSLT into XSL-FO

I have a document that has to be generated as PDF. 我有一个必须以PDF格式生成的文档。 I use Xalan and Apache FOP for processing an XML with XSLT into XSL-FO. 我使用Xalan和Apache FOP将带有XSLT的XML处理到XSL-FO中。

In my XML tree there is a node like this: 在我的XML树中,有一个像这样的节点:

<root>
    <formula>
        <text>3+10*10^-6*l</text>
        <html>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;3 &middot; + 10 &middot; 10&lt;sup&gt;-6&lt;/sup&gt; · &lt;i&gt;l&lt;/i&gt;&lt;/html&gt;</html>
    </formula>     
</root>

How can I not only get proper HTML (by using disable-output-escaping="yes" ) but also get a node-set ( exsl:node-set ?) that I can process later on? 如何不仅获得适当的HTML(通过使用disable-output-escaping="yes" ),而且还获得一个节点集( exsl:node-set ?),可以稍后对其进行处理? I mean, I want to get a XSL-FO representation of that HTML formula in order to integrate that into my PDF output. 我的意思是,我想获得该HTML公式的XSL-FO表示形式,以便将其集成到我的PDF输出中。

Something like 就像是

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

There may be a solution using saxon:parse() . 使用saxon:parse()可能有解决方案。 However, I cannot switch to that from Xalan-J. 但是,我不能从Xalan-J切换到该选项。

Is there a solution in my scenario? 我的方案有解决方案吗?

You can certainly write one stylesheet to process with Xalan that does 您当然可以编写一个样式表来处理Xalan

<xsl:template match="html">
  <xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>

which then creates a serialized result document with the XHTML markup. 然后使用XHTML标记创建序列化的结果文档。

A second stylesheet could then process the result document of the first stylesheet eg 然后,第二个样式表可以处理第一个样式表的结果文档,例如

<xsl:template match="xhtml:html" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <xsl:apply-templates/>
</xsl:template>

But you can't do it within one stylesheet with a result tree fragment as doe (disable-output-escaping) is a serialization feature and if you work with result tree fragments converted to a node set with the help of exsl:node-set or similar within one stylesheet there is no serialization happening. 但是您不能在一个带有结果树片段的样式表中完成此操作,因为doe (disable-output-escaping)是序列化功能,并且如果您使用exsl:node-set结果树片段转换为节点集,或一个样式表中的类似内容,则不会发生序列化。

Looking closer, as your snippet seems to contain references to undeclared entities like &middot; 仔细看看,您的代码段似乎包含对未声明实体的引用,例如&middot; I think the sample does not parse as XML at all so you would need to fix that first to do any XSLT processing. 我认为该示例根本不会解析为XML,因此您需要先进行修复以进行XSLT处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM