xsl-list
[Top] [All Lists]

Re: Need help rendering the HTML residing within the XML

2004-08-12 06:02:25
Hi Jeremy,

I need my XSL file to parse the XML so that the browser (IE 6+, NN
7+) will take these <b></b> tags and apply the appropiate HTML
formatting rather than treating them as XML nodes.

Make sure that you've designed your stylesheet to use
<xsl:apply-templates> rather than <xsl:value-of>. For example, you
should have a template like:

<xsl:template match="name">
  ...
  <xsl:apply-templates />
  ...
</xsl:template>

Given that, all you need to do is add a template that copies <b>
elements (and other HTML elements) into the output:

<xsl:template match="b">
  <b><xsl:apply-templates /></b>
</xsl:template>

Note that you should apply templates to the content of the <b>
elements in case they contain other elements nested inside them that
you also want to copy.

You *could* place the HTML elements in a separate namespace, but
there's no need to.

The browser seems to like character entity equivalents such as in
line 2 below and renders the <name> node in bold when I have
disable-output-escaping set to "yes".

Don't do it this way. It's ugly, might not work in all processing
environments, and there's a much better and simpler way (above) that
doesn't require any change to the source.

Cheers,

Jeni

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