Click to See Complete Forum and Search --> : XSLT (how to parse HTML within CDATA)


planetsim
09-26-2004, 09:06 AM
Ok for the past few weeks ive been playing around with XML/XSL,XSLT etc, and have come to a big brick wall which has no doors and its too high to climb over :p

Anyway getting to my point..

I have an XML file e.g.


<?xml version="1.0"?>
<person>
<name>Tim</name>
<info><![CDATA[<strong>T</strong>im is older then me]]></info>
<age>23</age>
</person>


Yea great example :glare: anyway now to where XML gets interesting XSLT

Now the result i want from this XSLT file is to parse that CDATA <strong> etc as HTML so Tim should be

Tim is older then me

Now the basic XSLT file for this example


<?xml version="1.0"?>
<!-- pretend i have an stylesheet declaration here -->
<person>
<name>Tim</name>
<info><![CDATA[<strong>T</strong>im is older then me]]></info>
<age>23</age>
</person>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/person">
Name: <xsl:value-of select="name" /><br />
Info: <xsl:value-of select="info" /><br />
Age: <xsl:value-of select="age" /><br />
</xsl:template>
</xsl:stylesheet>


*example probably doesnt work as i didnt test it :eek:

Ok however that will print something as follows



Name: Tim
Info: <strong>T</strong> is older then me
Age: 23


However i should be seeing something like this


Name: Tim
Info: Tim is older then me
Age: 23


Ive tried everything possible while keeping it valid, taking out the CDATA bit and using xsl:output with method html seems to work a test but im trying to keep it valid since its going to be used in an RSS Feed later on.

Ok so firstly is what i want possible?
is this going to be the worlds biggest hack job?
or should i just accept what i have or make it invalid?

Thanks.

piersk
09-26-2004, 09:09 AM
Take a look at this document (http://www.computing.surrey.ac.uk/personal/st/R.Peel/cs153/xsl1-1.pdf) (mainly pages 5-7). It is taken from the web publishing course that I took in my first year here at Uni and shows how to do XML/XSL stuff quite nicely.

planetsim
09-26-2004, 09:15 AM
Thanks for the PDF unfortunately no help for my situation :(

Weedpacket
09-27-2004, 07:55 AM
<xsl:value-of select="info" disable-output-escaping="yes">?
Maybe I'm just going wonky.

piersk
09-27-2004, 08:56 AM
Originally posted by Weedpacket
Maybe I'm just going wonky.

It's been said before... :D

planetsim
09-27-2004, 09:36 AM
I tried that also with <xsl:output> to no luck :( maybe i just have to be satisfied with XSLT not being this all great and wonderful thing or hope something is implemented that I want in the next version :glare:

Thanks anyways ;)