Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL: let raw HTML through

Tags:

html

xslt

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?

like image 815
BefittingTheorem Avatar asked Feb 04 '23 06:02

BefittingTheorem


1 Answers

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()" />
like image 93
Gabriele Petrioli Avatar answered Feb 06 '23 15:02

Gabriele Petrioli