Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Embed HTML in XML

Reply
Thread Tools

Embed HTML in XML

 
 
csgraham74
Guest
Posts: n/a
 
      06-13-2007
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Details">
<xsl:value-of select="//Data/Details" disable-output-escaping="yes"/
>

</xsl:template>
</xsl:stylesheet>

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      06-14-2007
csgraham74 wrote:
> 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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

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

</xsl:stylesheet>

///Peter

 
Reply With Quote
 
 
 
 
csgraham74
Guest
Posts: n/a
 
      06-14-2007
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Details">
<p>
<xsl:apply-templates select="Details"/>
</p>
</xsl:template>
<xsl:template match="Details">
<xsl:value-of select="//Data/Details" disable-output-escaping="yes"/
>

</xsl:template>
</xsl:stylesheet>

it

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      06-14-2007
On 13 Jun, 18:29, csgraham74 <(E-Mail Removed)> wrote:

> 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".

 
Reply With Quote
 
C.W.Holeman II
Guest
Posts: n/a
 
      06-14-2007
Peter Flynn wrote:
> csgraham74 wrote:
>> 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.


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"
xmlnshtml="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="emleretext" /></div>
<xsl:apply-templates
select="emle:control|emle:constant|emle:graphic" />
<div class="emlePostText">
<xsl:copy-of select="emleosttext" /></div>
</div>
</xsl:template>

The complete files are here:

http://emle.sourceforge.net/emle0201...le_lab_011.xml
http://emle.sourceforge.net/emle020100/emle_lab_011.xsl
http://emle.sourceforge.net/emle0201...quipment_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.

--
C.W.Holeman II | http://www.velocityreviews.com/forums/(E-Mail Removed)-5 http://JulianLocals.com/cwhii
To only a fraction of the human race does God give the privilege of
earning one's bread doing what one would have gladly pursued free, for
passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How hard is it to embed xml in an html page jalexa9898 XML 8 09-03-2006 04:18 PM
How to embed dynamic generated image into HTML? Olav Tollefsen ASP .Net 2 03-01-2004 03:14 PM
Re: embed image in html with mime encoding Jerry III ASP .Net 0 10-15-2003 07:39 AM
How to embed html in xml (i.e. prevent the html from being parsed)? Failure XML 1 09-07-2003 09:34 PM
embed an image in an HTML email. Helixpoint ASP .Net 1 07-16-2003 12:48 AM



Advertisments