[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Printing CDATA from feed as HTML


Subject: Re: [xsl] Printing CDATA from feed as HTML
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
Date: Fri, 13 Jun 2008 12:00:01 +0100

--------------------------------------------------
From: "Joelle Tegwen" <tegwe002@xxxxxxx>
Sent: Thursday, June 12, 2008 10:08 PM
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] Printing CDATA from feed as HTML

Using xsl 1.0 with php 5.x

I'm trying to consume an atom feed and I'd like to print out the full body of the content. It's wrapped in a CDATA section so I'm having trouble getting it to display correctly. The tags come out escaped despite adding the disable-output-escaping. I've looked via google and not found an answer.

Sites do this so it must be possible somehow. Right? Snippets below
Links to a manual to read are fine too.

Thanks!
Joelle

My XML snippet (Typical atom feed I'm guessing?) full feed at http://blog.lib.umn.edu/huntx010/ici/atom.xml:

<entry>
<title>(Further) Reflections on Green Living</title>
<link rel="alternate" type="text/html" href="http://blog.lib.umn.edu/huntx010/ici/2008/06/further_reflections_on_green_l.html" />
<link rel="service.edit" type="application/atom+xml" href="https://blog.lib.umn.edu/cgi-bin/mt-atom.cgi/weblog/blog_id=7828/entry_id=131252" title="(Further) Reflections on Green Living" />
<id>tag:blog.lib.umn.edu,2008:/huntx010/ici//7828.131252</id> <published>2008-06-11T19:48:09Z</published>
<updated>2008-06-11T19:49:00Z</updated>
<summary>Summer is a great time for taking stock of your eco-life, and for adding a little extra oomph to the good habits you already have. For example, are there any &quot;hard-copy&quot; activities you could do online, such as bill paying...</summary>
<author><name>Megan Dushin</name></author>
<category term="Tips from CEHD Insider" />
<content type="html" xml:lang="en" xml:base="http://blog.lib.umn.edu/huntx010/ici/">
<![CDATA[<p>Summer is a great time for taking stock of your<br />
eco-life, and for adding a little extra oomph to the good habits<br />
you already have. For example, are there any "hard-copy"<br />
activities you could do online, such as bill paying or travel<br />
planning? Do you need multiple light sources in your office, or<br />
would one do the job? Could you take mass transit to work two days<br />
a week instead of just one? Take time to ask reflective questions<br />
such as these--the Earth will thank you for it!</p>]]>
</content>
</entry>


My xsl snippet:


<xsl:template match="atom:entry[position() = 1]"> <h3> <xsl:apply-templates select="atom:title"/> <xsl:text> </xsl:text> <span class="feed_posted">Posted on: <xsl:apply-templates select="atom:updated"/></span> </h3> <xsl:value-of disable-output-escapting="yes" select="atom:content"/> </xsl:template>

It generates:

<h3><a href="http://blog.lib.umn.edu/huntx010/ici/2008/06/further_reflections_on_green_l.html">(Further) Reflections on Green Living</a>
<span class="feed_posted">Posted on: 06/11/2008</span></h3>
&lt;p&gt;Summer is a great time for taking stock of your&lt;br /&gt;
eco-life, and for adding a little extra oomph to the good habits&lt;br /&gt;
you already have. For example, are there any "hard-copy"&lt;br /&gt;
activities you could do online, such as bill paying or travel&lt;br /&gt;


planning? Do you need multiple light sources in your office, or&lt;br /&gt;
would one do the job? Could you take mass transit to work two days&lt;br /&gt;
a week instead of just one? Take time to ask reflective questions&lt;br /&gt;
such as these--the Earth will thank you for it!&lt;/p&gt;



I want (We'll I'd really like to strip out the <br /> tags, but I think I can do that. The part I'm struggling with is the escaping):


<h3><a href="http://blog.lib.umn.edu/huntx010/ici/2008/06/further_reflections_on_green_l.html">(Further) Reflections on Green Living</a>
<span class="feed_posted">Posted on: 06/11/2008</span></h3>
<p>Summer is a great time for taking stock of your<br />
eco-life, and for adding a little extra oomph to the good habits<br />
you already have. For example, are there any "hard-copy"<br />
activities you could do online, such as bill paying or travel<br />
planning? Do you need multiple light sources in your office, or<br />
would one do the job? Could you take mass transit to work two days<br />
a week instead of just one? Take time to ask reflective questions<br />
such as these--the Earth will thank you for it!</p>



I think one thing that needs to be cleared up is "Is the pseudo-markup in the CDATA section guaranteed to be xhtml as opposed to html?", it appears to me that it might not be XML so parsing it might fail.


Joe
http://joe.fawcett.name



Current Thread
Keywords