如何使用 XSLT 将一些标签转换为另一些标签 [英] How to transform some tags to another using XSLT

查看:27
本文介绍了如何使用 XSLT 将一些标签转换为另一些标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 xml:

<box>
   <title>bold text</title>
   some text
</box>

以及以下 xsl:

<xsl:template match="box">
    <p style="background:red;">
        <xsl:apply-templates/>
    </p>
</xsl:template>

<xsl:template match="title">
    <p style='background:green;'>
        <xsl:apply-templates/>
    </p>
</xsl:template>

我得到了以下信息:

<p style="background:red;"> </p>
<p style="background:green;">bold text</p>
some text
<p></p>

但我想要以下内容:

<p style="background:red;">
   <p style="background:green;">bold text</p>
   some text
</p>

我该怎么做?

推荐答案

当我运行这个 xslt/xml 我得到这个结果:

When I run this xslt/xml I get this result:

XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="box">
    <p style="background:red;">
        <xsl:apply-templates/>
    </p>
  </xsl:template>

  <xsl:template match="title">
    <p style='background:green;'>
        <xsl:apply-templates/>
    </p>
  </xsl:template>
</xsl:stylesheet>

XML 输出:

<?xml version="1.0"?>
<p style="background:red;">
   <p style="background:green;">bold text</p>
   some text
</p>

这就是你想要的正确吗?

This is what you want correct?

这篇关于如何使用 XSLT 将一些标签转换为另一些标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆