tags:

views:

122

answers:

1

Im making a XSL transform. The XML I'm transforming has a node which contains html.

<xml>
    <text>
        <p><b>Hello</b><em>There</em></p>
    </text>
</xml>

Applying the transform:

<xsl:template match="text">
    <div class="{name()} input">
        <xsl:value-of select="."/>
    </div>
</xsl:template>

I get the output:

<div class="text input">
    Hello There
</div>

But I want the Html to remain intact like so:

<div class="text input">
    <p><b>Hello</b><em>There</em></p>
</div>

Substituting . with the node() function gives the same result.

Is there a method of getting the HTML through the transform unmodified?

+4  A: 

Have a look at xsl:copy-of

It should do what you need..

<xsl:copy-of select="." />

The above will select the whole current node so in your case the <text> itself will be included..

Use the following to select everything under the current..

<xsl:copy-of select="child::node()" />
Gaby
`<xsl:copy-of select="." />` would copy the entire `<text>` node, not just its contents. ;)
Tomalak
@Tomalak, indeed.. edited with alternate version ..
Gaby
Thanks Gaby, that did the trick nicely ;)
Brian Heylin
Oh by the way: the child axis is implicit. This means `<xsl:copy-of select="child::node()" />` and `<xsl:copy-of select="node()" />` are equivalent.
Tomalak