Re: How to embed HTML in XML

Subject: Re: How to embed HTML in XML
From: Vernon_Imrich@xxxxxxxxxxxxxx
Date: Wed, 2 Aug 2000 09:16:14 -0400
>Date: Tue, 1 Aug 2000 11:26:54 -0700
>From: "Amit Aggarwal" <amit.aggarwal@xxxxxxxxxx>
>Subject: How to embed HTML in XML
>    I want to embed HTML into an XML.The problem which I am facing is that the
>XSLT processor gives errors for HTML tags and forces me to define them in
>the DTD.
>Is there some simple way in which I can make the XSLT processor to ignore
>the HTML tags and I dont have to define it in the DTD.

There are two parts to the problem.  First, you need to make the embedded HTML
markup appear as character data inside of an XML field when the XML is parsed.
Second you need the XSL processor to preserve the character information and
not try to escape special characters (e.g. convert "<" to "&lt;") in the output
when it does the "value-of" operation on that field.

Use the CDATA (character data) wrapper to solve problem 1.  The syntax for
this is: <![CDATA[ ...text here... ]]>

     <myfield> <![CDATA[ <p>some text<br>more here</p> ]]> </myfield>

To solve problem 2, use the "disable-output-escaping" flag in your XSL.  This
flag is supported for the key things like "value-of" that dump XML field values
into the ouput.

Example (assuming proper node context):

<xsl:value-of select="myfield" disable-output-escaping="yes"/>

BTW, this is a perfectly reasonable thing to be doing.  There are many contexts
where the value of an XML field really does need some internal markup preserved,
for data integrity reasons at least.  It also makes sense that you need to tell
the XML parser and the XSL processor explicitly in those cases that the "markup"
is part of the data for that field.

 XSL-List info and archive:

Current Thread