Embed HTML in XML

C

csgraham74

Ok - i was wondering if someone could help me.

im basically trying to embed an html string in piece of XML. i
created an xsl and added the CDATA into the xml around the html i wish
to render. In my calling page i create an XML data island (excuse the
terminology as im new to this stuff) to pull in the xml fields and
to hopefully render the html as xml (see Details node ) .
Unfortunately this doesnt work and it just displays as a string
output.

If anyone could give me some assistnace on this it would be a great
help, if im totally barking up the wrong tree please tell me.

the only thing i must say is that i need to creata HTML inside the XML
node as im using a third party control to create this.

My current output is a table with all fields pulling in corrctly
except the details node.

Any help on this appreciated.

XML DATA ISLAND
<xml id="cdcat" src="/experience/includes/test.xml"></xml>
<table border="1" datasrc="#cdcat">

<tr>
<td><span datafld="Title"></span></td>
<td><span datafld="Date"></span></td>
<td><span datafld="Info"></span></td>
<td><span datafld="Details"></span></td>
</tr>

XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<Data>
<Title>Test 1</Title>
<Date>20th June 2007</Date>
<Info>ghsdgfhsdgfh fdsfhjsdfhjh fsdfjhsdfjhhfjh fhsjdfhjshdfjhj
sjdfhjsdhfjhj fhjshdfsdj jdfhjhsdfhhfhsf</Info>
<Details><!
[CDATA[<P>xxxxx<BR>hfsjdhjsdfh<BR><BR>sdfjksjdfkksfj<BR><BR>sdfjmsdfsdfj<BR><BR><BR>sdfjskjdfkjskjfksj<BR></
P>]]></Details>
</Data>

XSL

<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:template>
</xsl:stylesheet>
 
P

Peter Flynn

csgraham74 said:
Ok - i was wondering if someone could help me.

im basically trying to embed an html string in piece of XML. i
created an xsl and added the CDATA into the xml around the html i wish
to render.

Don't. Leave it as normal markup and add suitable templates to your XSL
to handle it.

See the FAQ: http://xml.silmaril.ie/authors/html/

XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<Data>
<Title>Test 1</Title>
<Date>20th June 2007</Date>
<Info>ghsdgfhsdgfh fdsfhjsdfhjh fsdfjhsdfjhhfjh fhsjdfhjshdfjhj
sjdfhjsdhfjhj fhjshdfsdj jdfhjhsdfhhfhsf</Info>
<Details>
<P>xxxxx<BR/>hfsjdhjsdfh<BR/>
<BR/>sdfjksjdfkksfj<BR/>
<BR/>sdfjmsdfsdfj<BR/>
<BR/><BR/>sdfjskjdfkjskjfksj<BR/></P>
</Details>
</Data>

then

XSL

<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="Details">
<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

///Peter
 
C

csgraham74

thanks peter - i really appreciate the help

i have created the following template and it displays the xml
correctly when i open my .xml document in my browser.

However when i try to embed this in html it still displays as before -
why is this happening ?? can i apply my style from with my HTML
document ????

<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Details">
<p>
<xsl:apply-templates select="Details"/>
</p>
</xsl:template>
</xsl:template>
</xsl:stylesheet>

it
 
A

Andy Dingley

im basically trying to embed an html string in piece of XML.

Looks more like you're having trouble putting XML into HTML.
i create an XML data island

An obsolete and non standards-based M$oft technique that's best
avoided. Look at the AJAX route, not "data islands".

If embedding HTML inside your XML is also a problem, then look at how
RSS does it (mainly by encoding "<" as "&lt;" etc.). There's a
famously good web page out there on "diveintomark" called "The myth of
RSS version compatibility".
 
C

C.W.Holeman II

Peter said:
Don't. Leave it as normal markup and add suitable templates to your XSL
to handle it.

This was exactly what I was looking for but had not yet taken the time
to create a clean posting. Thank you.

I needed to add the namespace for XHTML to get it to work for me. Here
is a fragment from one my XML files where the <pretext> element may
include XHTML content.

<equipment xmlns="http://emle.sourceforge.net/emle020100"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<id>3</id>
<title>Solid Rectangle Fraction</title>
<value>
<pretext>
<xhtml:em>Unsegmented</xhtml:em> rectangle selectable by the
enclosed buttons.
</pretext>

Here is a slightly edited fragment from the XSLT file that passes the
XHTML content within <pretext> to the output file:

<xsl:template match="emle:value">
<div class="emleValue">
<div class="emlePreText"><xsl:copy-of select="emle:pretext" /></div>
<xsl:apply-templates
select="emle:control|emle:constant|emle:graphic" />
<div class="emlePostText">
<xsl:copy-of select="emle:posttext" /></div>
</div>
</xsl:template>

The complete files are here:

http://emle.sourceforge.net/emle020100/lab/emle_lab_011.xml
http://emle.sourceforge.net/emle020100/emle_lab_011.xsl
http://emle.sourceforge.net/emle020100/equipment/emle_equipment_3.xml

I am using "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4)
Gecko/20070515 Firefox/2.0.0.4" which may be needed for the pages to
display.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top