Forum Moderators: open

Message Too Old, No Replies

insert HTML in an XML document

actual HTML

         

WhosAWhata

4:54 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



if i have a XML file like this
<article>
<num></num>
<title>this is a the opening page</title>
<desc>A starter page</desc>
<info>ACTUAL HTML CODE INCLUDING <a> LINKS and <br>tags</info>
</article>
<article>
<num>1</num>
<title>Article 1</title>
<desc>a sample article</desc>
<info>HTML with <img><p><br><hr> basically any HTML</info>
</article>

how do I include this html (which will be generated from a WYSIWYG form passed through PHP to write this file)
i think XML will typically try to parse these <HTML> tags, how do i keep them as actual HTML when they are parsed by the XSL style sheet?

drbrain

5:02 pm on Jun 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the XHTML namespace, and well-formed XHTML, or wrap it in a CDATA section:

<info><html xmlns="http://www.w3.org/1999/xhtml">...</html></info>

<info><![CDATA[...]]></info>

Then write an XSL template to pass the info element's contents straight through.

choster

5:04 pm on Jun 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can indicate blocks for the parser to ignore by encapsulating them within CDATA, to wit

<info><![CDATA[HTML with <img><p><br><hr> basically any HTML]]></info>

The parser will completely ignore everything after <![CDATA[ until it encounters ]]> , so will not be able to parse any XML elements inside.

Alternatively, I suppose you could escape the troublemaking characters or maybe wrap it in <xsl:text>, but I think the whether and how would be processor-dependent.

davidpbrown

1:14 pm on Jun 14, 2004 (gmt 0)

10+ Year Member



or simply replacing < with &lt; and > with &gt; should also work.
If transforming into another XML document using <xsl:value-of select="." disable-output-escaping = "yes"/> to preserve the characters rather than having them outputed as <>

davidpbrown

1:32 pm on Jun 14, 2004 (gmt 0)

10+ Year Member



or are you looking to actually insert the HTML into the output as HTML? In which case I expect you would need to transform the text adding the <html nodes> where suggested by the text.