[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Translating the contents of a XML field as HTML...

Subject: Re: Translating the contents of a XML field as HTML...
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 10 Jan 2003 11:32:43 +0000
xml field
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>
    &lt;b&gt;example text&lt;/b&gt;
  </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 &lt;.

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.