Subject: Re: Embedding HTML in XML From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 04 Aug 2000 21:31:37 +0100 |
Madhu, >But instead of getting an image in the HTML page, I get the exact CDATA >text written as is to the browser. Is there some way I can embed the HTML >in the XML markup so that it's processed as HTML itself? CDATA sections are designed to take the trauma out of escaping text that has lots of characters that need escaping in (like < and &). Putting <![CDATA[...]]> round a section essentially says "do not parse this section - everything in it should be interpreted as characters". So, in your example: <![CDATA[ <img src="global.gif" alt="Go around the world" /> ]]> is exactly the same as: <img src="global.gif" alt="Go around the world" /> The XML parser sees a string, not a tag. The XSLT processor therefore sees a string, not a tag, and processes it as a string, not a tag, which means that it outputs: <img src="global.gif" alt="Go around the world" /> which gets displayed in your browser. The goal you're aiming for is copying something that you have in your XML source directly into your HTML output. The xsl:copy-of element is designed precisely for this purpose. xsl:copy-of will give an exact copy of whatever you select, including attributes and content. So, you can just have XML like: <page> We offer the cheapest air fares to Bombay. <img src="global.gif" alt="Go around the world" /> </page> And then a template that says 'when you come across an img element, just copy it': <xsl:template match="img"> <xsl:copy-of select="." /> </xsl:template> If you have lots of HTML that you want to copy straight over from your XML source to your HTML output, the cleanest approach is to define an 'html' namespace and mark all the HTML elements as belonging to this namespace: <page xmlns:html="http://www.w3.org/1999/xhtml"> We offer the cheapest air fares to Bombay. <html:img src="global.gif" alt="Go around the world" /> </page> To copy these HTML elements whenever you come across them within your page, have a template that matches them (html:* - any element in the html namespace) and copies them: <xsl:template match="html:*"> <xsl:copy-of select="." /> </xsl:template> I hope this helps, Jeni Dr Jeni Tennison Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Embedding HTML in XML, Madhu Menon | Thread | RE: Embedding HTML in XML, Kay Michael |
Re: Standard XPath expression for t, Mike Brown | Date | RE: <xsl:stylesheet xmlns..., Evan Lenz |
Month |