我正在使用xslt-1.0将input.xml下面的内容转换为output.xml。我在获取节点名称作为不同节点的值时遇到困难。请在下面找到input.xml并帮助我获取output.xml。提前致谢。
请注意,某些节点值是富文本数据,而有些则不是。
input.xml:
<Presentation>
<MainDescription>
<![CDATA[
<p>Line1 The main description text goes here.</p>
<p>Line2 The main description text goes here.</p>
<p><img alt="" src="_9c3778a0-d596-4eef-85fa-052a5e1b2166.jpg" width="322" height="100"/></p>
]]>
</MainDescription>
<KeyConsiderations>
<![CDATA[
<p>Line1 The key consideration text goes here.</p>
<p><img alt="" src="_9c3778a0-d596-4eef-85fa-052a5e1b2166.jpg" width="322" height="100"/></p>
<p>Line2 The key consideration text goes here.</p>
]]>
</KeyConsiderations>
<Skills>
<p>Line1 The Skills text goes here.</p>
<p>Line2 The Skills text goes here.</p>
<p>Line3 The Skills text goes here.</p>
</Skills>
<Synonyms>
<p>The Synonyms text goes here.</p>
</Synonyms>
</Presentation>
output.xml:
<ATTRIBUTE-VALUE>
<THE-VALUE>
<div xmlns="http://www.w3.org/1999/xhtml">
<h1>Main Description</h1>
<p>Line1 The main description text goes here.</p>
<p>Line2 The main description text goes here.</p>
<p><img alt="" src="_9c3778a0-d596-4eef-85fa-052a5e1b2166?accept=none&private" width="322" height="100"/></p>
<h1>Key Consideration</h1>
<p>Line1 The key consideration text goes here.</p>
<p><img alt="" src="_9c3778a0-d596-4eef-85fa-052a5e1b2166?accept=none&private" width="322" height="100"/></p>
<p>Line2 The key consideration text goes here.</p>
<h1>Skills</h1>
<p>Line1 The Skills text goes here.</p>
<p>Line2 The Skills text goes here.</p>
<p>Line3 The Skills text goes here.</p>
<h1>Synonyms</h1>
<p>The Synonyms text goes here.</p>
</div>
</THE-VALUE>
</ATTRIBUTE-VALUE>
答案 0 :(得分:0)
您似乎想取消转义那些元素的内容。这可以通过disable-output-escaping
完成-如果您的XSLT处理器支持它(浏览器集成处理器通常不支持,独立处理器通常支持)。
例如此模板:
<xsl:template match="MainDescription">
<h1>Main Description</h1>
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>
将样本中的<MainDescription>
转换为:
<h1>Main Description</h1>
<p>Line1 The main description text goes here.</p>
<p>Line2 The main description text goes here.</p>
<p><img alt="" src="_9c3778a0-d596-4eef-85fa-052a5e1b2166.jpg" width="322" height="100"/></p>
为其他元素创建更多此类模板。
没有disable-output-escaping
,模板的输出将是这样:
<h1>Main Description</h1>
<p>Line1 The main description text goes here.</p>
<p>Line2 The main description text goes here.</p>
<p><img alt="" src="_9c3778a0-d596-4eef-85fa-052a5e1b2166.jpg" width="322" height="100"/></p>
相当于初始CDATA
部分的100%,这只是另一种写法。顺便说一句,这不是“ RTF”。这是文字,仅此而已。恰好包含一些尖括号的文本。