[thelist] preserving HTML in XSL

Eric Vitiello evolt at perceive.net
Thu Jan 24 14:09:00 CST 2002

-- Alister Cameron [Thu, 24 Jan 2002 23:56:37 +1100]:
>SUMMARY: I am looking for the generic how-to answer for including a
>chunk of pre-prepared HTML in an XML file so that when the XML file is
>transformed into HTML for the client (I'm just working with v4 and up web browser
>clients here), the HTML slots into the rest of what the xsl
>stylesheet has spat out, all as HTML to be rendered by the browser... no escaped

how about this:

------ XML ------

<?xml version="1.0"?>
    <title>This is the title</title>
        <h1>This is the content</h1>
        and will be displayed with all of the <b>proper formatting</b> that is placed in this node.


-------- XSL -----------
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output encoding="iso-8859-1" method="html" indent="yes"/>
    <xsl:template match="/item">
                <title><xsl:value-of select="title"/></title>
                <xsl:value-of select="content" disable-output-escaping="yes"/>

I haven;t tested this specific code, but I do this all day long, so it should work without much headache.

the key is the <![CDATA[ ]]>  block, which tells the XSL not to parse the data inside, and the disable-output-escaping="yes"  which tells the XSL not to turn thigns like < into &lt;

Eric Vitiello
Perceive Designs

More information about the thelist mailing list