Re: [xsl] mystery #3: rendering embedded HTML

Subject: Re: [xsl] mystery #3: rendering embedded HTML
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sat, 13 Apr 2002 16:24:16 +0100
Hi Gary,

> Isn't it odd that while there is a solution for embedding verbatim
> markup inside XML, there is apparently no solution for extracting
> it?

You can use disable-output-escaping in this situation. When you get
the value of the escaped HTML using xsl:value-of, add a
disable-output-escaping attribute with the value "yes" to the
instruction. For example, if you have this:

  <envelope>
    <![CDATA[
      <p>My mal-formed HTML.<br>
    ]]>
  </envelope>

then you can extract it with:
  
  <xsl:value-of select="envelope" disable-output-escaping="yes" />

and you'll get:

  <p>My mal-formed HTML.<br>

as the result, or at least you will in those processors that generate
a character output stream rather than a DOM tree.

If this HTML makes up the majority of your page, the other option is
to use the text output method rather than the XML output method:

<xsl:output method="text" />

and generate everything else in the page as a string as well. Then you
don't need to disable output escaping because there's no output
escaping to disable in the first place.

But the best solution is nevertheless to tidy up the HTML so that it's
well-formed. This would also give you more control over what users
entered -- you can insist that they enter well-formed XHTML and you
can validate that XHTML to make sure it's at the correct level (for
example that they don't enter an 'html' element when you're expecting
elements that are valid within a 'div').

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread