开发者

How to transform some tags to another using XSLT

开发者 https://www.devze.com 2023-02-27 20:26 出处:网络
I have the following xml: <box> <title>bold text</title> some text </box> and the following xsl:

I have the following xml:

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

and the following 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>

And I got 开发者_如何学Cfollowing:

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

But I want following:

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

How do I do this?


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 Output:

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

This is what you want correct?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号