XSLT处理包含HTML文本的XML元素
我有XML格式的对象的详细信息 MyObject是具有属性的类的名称,比如说:objectInformation。 它以XML格式存储在数据库中。 当我从DB中提取read时,我得到的输出低于XSLT处理包含HTML文本的XML元素,xml,xslt,Xml,Xslt,我有XML格式的对象的详细信息 MyObject是具有属性的类的名称,比如说:objectInformation。 它以XML格式存储在数据库中。 当我从DB中提取read时,我得到的输出低于 <MyObject objectInformation="<node1><node2>some Information here</node2><node3><![CDATA[<TEXTFOR
<MyObject objectInformation="<node1><node2>some Information here</node2><node3><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="11" COLOR="#403F3F" LETTERSPACING="0" KERNING="0"><B><I>comment in for new object</I></B></FONT></P></TEXTFORMAT>]]></node3><node4>07/18/2013</node4></node1>"</MyObject>
您发布的代码片段甚至不是格式良好的XML,MyObject
start标记缺少
,因此您需要的不是您发布的内容
<MyObject objectInformation="<node1><node2>some Information here</node2><node3><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="11" COLOR="#403F3F" LETTERSPACING="0" KERNING="0"><B><I>comment in for new object</I></B></FONT></P></TEXTFORMAT>]]></node3><node4>07/18/2013</node4></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错误)。(您缺少一个>来关闭开始标记)尝试了所有选项,但无效。我无法获取callsaxon: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="<node1><node2>some Information here</node2><node3><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="11" COLOR="#403F3F" LETTERSPACING="0" KERNING="0"><B><I>comment in for new object</I></B></FONT></P></TEXTFORMAT>]]></node3><node4>07/18/2013</node4></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