tags:

views:

131

answers:

2

What code could I use in replace of <xsl:copy-of select="tag"/>, that when applied to the following xml..

<tag>
  content
  <a>
    b
  </a>
</tag>

..would give the following result: ?

content
<a>
  b
</a>

I wish to echo out all the content therein, but excluding the parent tag


Basically I have several sections of content in my xml file, formatted in html, grouped in xml tags
I wish to conditionally access them & echo them out
For example: <xsl:copy-of select="description"/>
The extra parent tags generated do not affect the browser rendering, but they are invalid tags, & I would prefer to be able to remove them
Am I going about this in totally the wrong way?

+7  A: 

Since you want to include the content part as well, you'll need the node() function, not the * operator:

<xsl:copy-of select="tag/node()"/>

I've tested this on the input example and the result is the example result:

content
<a>
  b
</a>
Welbog
Perfect. Didn't realise it would be that simple. Thank you :]
ProPuke
+2  A: 

Complementing Welbog's answer, which has my vote, I recommend writing separate templates, along the lines of this:

<xsl:template match="/">
  <body>
    <xsl:apply-templates select="description" />
  </body>
</xsl:template>

<xsl:template match="description">
  <div class="description">
    <xsl:copy-of select="node()" />
  </div>
</xsl:template>
Tomalak
Rashmi Pandit