我使用XSLT1.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>发布于 2018-10-05 15:28:26
您似乎希望取消转义这些元素的内容。这可以用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部分,这只是另一种编写方式。顺便说一句,这不是“富文本”。只是文本,没别的了。恰好包含几个尖括号的文本。
https://stackoverflow.com/questions/52644026
复制相似问题