首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSLT-1.0将节点名称设置为不同节点中的值

XSLT-1.0将节点名称设置为不同节点中的值
EN

Stack Overflow用户
提问于 2018-10-04 18:06:18
回答 1查看 96关注 0票数 0

我使用XSLT1.0将下面的input.xml转换为output.xml。我在获取节点名称作为不同节点的值时遇到了困难。请找到下面的input.xml并帮助我获取output.xml。提前谢谢。

请注意,有些节点值是富文本数据,有些则不是。

input.xml:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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&amp;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&amp;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>
EN

回答 1

Stack Overflow用户

发布于 2018-10-05 15:28:26

您似乎希望取消转义这些元素的内容。这可以用disable-output-escaping实现--如果您的XSLT处理器支持它的话(集成浏览器的处理器通常不支持,独立的处理器通常支持)。

例如,此模板:

代码语言:javascript
复制
<xsl:template match="MainDescription">
    <h1>Main Description</h1>
    <xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>

会将你的样本中的<MainDescription>转换为:

代码语言:javascript
复制
<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,模板的输出将如下所示:

代码语言:javascript
复制
<h1>Main Description</h1>

        &lt;p&gt;Line1 The main description text goes here.&lt;/p&gt;
        &lt;p&gt;Line2 The main description text goes here.&lt;/p&gt;
        &lt;p&gt;&lt;img alt="" src="_9c3778a0-d596-4eef-85fa-052a5e1b2166.jpg" width="322" height="100"/&gt;&lt;/p&gt;

这完全等同于初始的CDATA部分,这只是另一种编写方式。顺便说一句,这不是“富文本”。只是文本,没别的了。恰好包含几个尖括号的文本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52644026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档