XSL: let raw HTML through

2019-04-24 17:50发布

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?

标签: html xslt
1条回答
2楼-- · 2019-04-24 18:24

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()" />
查看更多
登录 后发表回答