How do I Emit Escaped XML representation of a Node in my XSLT's HTML Output

Posted by Emmanuel on Stack Overflow See other posts from Stack Overflow or by Emmanuel
Published on 2010-04-14T14:50:18Z Indexed on 2010/04/14 14:53 UTC
Read the original article Hit count: 341

Filed under:

I'm transforming XML to an HTML document. In this document I want to embed XML markup for a node that was just transformed (the HTML document is a technical spec).

For example, if my XML was this:

<transform-me>
    <node id="1">
        <stuff type="floatsam">
           <details>Various bits</details>
        </stuff>
    </node>
</transform-me>

I'd want my XSLT output to look something like this:

<h1>Node 1</h1>
   <h2>Stuff (floatsam)</h2>
   Various bits
   <h2>The XML</h2>
   &lt;stuff type=&quot;floatsam&quot;&gt;
      &lt;details&gt;Various bits&lt;/details&gt;
   &lt;/stuff&gt;

I'm hoping there is an XSLT function that I can call in my <stuff> template to which I can pass the current node (.) and get back escaped XML markup for <stuff> and all its descendants. I have a feeling unparsed-text() might be the way to go but can't get it to work.

© Stack Overflow or respective owner

Related posts about xslt