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处理包含HTML文本的XML元素_Xml_Xslt - Fatal编程技术网

XSLT处理包含HTML文本的XML元素

XSLT处理包含HTML文本的XML元素,xml,xslt,Xml,Xslt,我有XML格式的对象的详细信息 MyObject是具有属性的类的名称,比如说:objectInformation。 它以XML格式存储在数据库中。 当我从DB中提取read时,我得到的输出低于 <MyObject objectInformation="&lt;node1>&lt;node2>some Information here&lt;/node2>&lt;node3>&lt;![CDATA[&lt;TEXTFOR

我有XML格式的对象的详细信息

MyObject是具有属性的类的名称,比如说:objectInformation。 它以XML格式存储在数据库中。 当我从DB中提取read时,我得到的输出低于

<MyObject objectInformation="&lt;node1>&lt;node2>some Information here&lt;/node2>&lt;node3>&lt;![CDATA[&lt;TEXTFORMAT LEADING=&quot;2&quot;>&lt;P ALIGN=&quot;LEFT&quot;>&lt;FONT FACE=&quot;Verdana&quot; SIZE=&quot;11&quot; COLOR=&quot;#403F3F&quot; LETTERSPACING=&quot;0&quot; KERNING=&quot;0&quot;>&lt;B>&lt;I>comment in for new object&lt;/I>&lt;/B>&lt;/FONT>&lt;/P>&lt;/TEXTFORMAT>]]>&lt;/node3>&lt;node4>07/18/2013&lt;/node4>&lt;/node1>"</MyObject>

您发布的代码片段甚至不是格式良好的XML,
MyObject
start标记缺少
,因此您需要的不是您发布的内容

<MyObject objectInformation="&lt;node1>&lt;node2>some Information here&lt;/node2>&lt;node3>&lt;![CDATA[&lt;TEXTFORMAT LEADING=&quot;2&quot;>&lt;P ALIGN=&quot;LEFT&quot;>&lt;FONT FACE=&quot;Verdana&quot; SIZE=&quot;11&quot; COLOR=&quot;#403F3F&quot; LETTERSPACING=&quot;0&quot; KERNING=&quot;0&quot;>&lt;B>&lt;I>comment in for new object&lt;/I>&lt;/B>&lt;/FONT>&lt;/P>&lt;/TEXTFORMAT>]]>&lt;/node3>&lt;node4>07/18/2013&lt;/node4>&lt;/node1>"></MyObject>
给你一个更完整的例子,当我应用样式表时

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:saxon="http://saxon.sf.net/"
  exclude-result-prefixes="saxon"
  version="2.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="MyObject">
  <xsl:apply-templates select="saxon:parse(@objectInformation)/node()"/>
</xsl:template>

<xsl:template match="node3">
  <xsl:apply-templates select="saxon:parse(.)/node()"/>
</xsl:template>

<xsl:template match="TEXTFORMAT">
  <fo:block>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<xsl:template match="P">
  <fo:block>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

</xsl:stylesheet>

我意识到这不是一个完整有效的XSL-FO文档,但它显示了在输入中转义然后通过
saxon:parse
解析的元素模板被调用。因此,您只需要添加更多的模板来根据需要转换其他元素,并创建一个有效的XSL-FO文档,如果您需要这方面的帮助,我建议您提出一个新问题,概述在解析输入元素后,您希望输入元素的FO结构(即,您希望如何转换这些
节点
元素以及如何转换这些HTML元素),然后希望比我更精通XSL-FO的人能够提供帮助。

我不确定您是否犯了复制粘贴错误,但您给出的示例XML格式不正确(这可能会声明saxon错误)。(您缺少一个>来关闭开始标记)尝试了所有选项,但无效。我无法获取call
saxon:parse(.)/node()的输出
到一个变量中。.在运行saxon解析器之前,是否需要进行任何系统配置?是否需要下载任何jar文件来运行?@ShrihariJ,我添加了一个使用saxon 9.1尝试过的更完整的示例。它也应该适用于saxon 9.4或9.5等更高版本,但只有在使用商业版(EE或PE)时才适用不幸的是,这些扩展函数在开源版本中不可用。
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:saxon="http://saxon.sf.net/"
  exclude-result-prefixes="saxon"
  version="2.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="MyObject">
  <xsl:apply-templates select="saxon:parse(@objectInformation)/node()"/>
</xsl:template>

<xsl:template match="node3">
  <xsl:apply-templates select="saxon:parse(.)/node()"/>
</xsl:template>

<xsl:template match="TEXTFORMAT">
  <fo:block>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<xsl:template match="P">
  <fo:block>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

</xsl:stylesheet>
<MyObject objectInformation="&lt;node1>&lt;node2>some Information here&lt;/node2>&lt;node3>&lt;![CDATA[&lt;TEXTFORMAT LEADING=&quot;2&quot;>&lt;P ALIGN=&quot;LEFT&quot;>&lt;FONT FACE=&quot;Verdana&quot; SIZE=&quot;11&quot; COLOR=&quot;#403F3F&quot; LETTERSPACING=&quot;0&quot; KERNING=&quot;0&quot;>&lt;B>&lt;I>comment in for new object&lt;/I>&lt;/B>&lt;/FONT>&lt;/P>&lt;/TEXTFORMAT>]]>&lt;/node3>&lt;node4>07/18/2013&lt;/node4>&lt;/node1>"></MyObject>
<?xml version="1.0" encoding="UTF-8"?>some Information here<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:block>comment in for new object</fo:block>
</fo:block>07/18/2013