Hi Phil,
I've been using XSL for only a week, but I am progressing quite
well...I have a program which uses web pages as its interface, and
part of the program requires an XML file with fields containing
strings which themselves contain HTML to be included on the HTML
output.
The only problem is the string from the XML file is displayed as-is,
for example;
field value is, say: "<b>example text</b>"
But instead of being displayed as the text "example text" in bold,
it is displayed as "<b>example text</b>".
That is, you have some HTML embedded in XML like:
<data>
<![CDATA[<b>example text</b>]]>
</data>
or:
<data>
<b>example text</b>
</data>
and you want to string value of the <data> element to be inserted
without the normal escaping that would go on, so that the less-than
sign in the text of the <data> element is output as an actual
less-than sign rather than an escaped <.
To do this you need to disable output escaping using the
disable-output-escaping attribute on the xsl:value-of element. For
example:
<xsl:template match="data">
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>
However, it is better by far if you can to get the XML that you're
processing changed so that the HTML elements in the XML are actually
stored as elements, i.e. so that it looks like:
<data>
<b>example text</b>
</data>
Then you can just use:
<xsl:template match="data">
<xsl:copy-of select="node()" />
</xsl:template>
The disadvantage with using disable-output-escaping is that not all
processors support it and it won't be used if the processor doing the
transformation is not also in charge of doing the serialisation of the
result. The advantage of storing the HTML as actual HTML in your XML
is that the HTML is then more accessible to XSLT processing; for
example, you could easily then transform your <b> elements into
<strong> elements with:
<xsl:template match="data">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="b">
<strong><xsl:apply-templates /></strong>
</xsl:template>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list