Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / August 2005

Tip: Looking for answers? Try searching our database.

HTML tags within XML element rendered to HTML document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marek - 05 Aug 2005 11:16 GMT
Hi
What I need to do is to take the following XML (or some variant of it):
<?xml version="1.0" encoding="UTF-8"?>
<MyRawHTML>
 <H1>Hello, world!</H1>
</MyRawHTML>

And apply an XSLT to it along the lines of:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
 <head>
 </head>
 <body>
   <p>
     <xsl:value-of select="/MyRawHTML" />

     <!-- This doesn't work either:
       <![CDATA[<H1>Hello, world!</H1>]]>
     -->

   </p>
 </body>
</html>
</xsl:template>
</xsl:stylesheet>

So that I get:

<html>
 <head>
 </head>
 <body>
   <p>
     <H1>Hello, world!</H1>
   </p>
 </body>
</html>

Is this possible?  I have tried to use CDATA, but I just get the text
"<H1>Hello, world!</H1>" coming through instead.

Thank you for any help anyone can provide.

Marek
Pascal Schmitt - 05 Aug 2005 12:17 GMT
Hello!

> What I need to do is to take the following XML (or some variant of it):
> <?xml version="1.0" encoding="UTF-8"?>
> <MyRawHTML>
>   <H1>Hello, world!</H1>
> </MyRawHTML>

Value-Of is wrong here, it converts everything to a string (if you put
it here).

Use copy-of:
        <xsl:copy-of select="/MyRawHTML/*/node()" />

This copies all the content of MyRawHTML, including Attributes to the
output.

Beware of namespace problems!

<MyRawHTML xmlns="urn:foo">
  <h1>Hello, world!</h1>
</MyRawHTML>

Will give you this:

<html xmlns="http://www.w3.org/1999/xhtml/">
  <body>
    <h1 xmlns="urn:foo">Hello, world!</h1>
  </body>
</html>

This means, that the h1-Element is not an HTML-Element and will not be
rendered as you thought by some browsers (Mozilla).

This will give you the output you wish:

<MyRawHTML xmlns="urn:foo">
  <h1 xmlns="http://www.w3.org/1999/xhtml/>Hello, world!</h1>
</MyRawHTML>

Signature

Pascal Schmitt

Deepak - 05 Aug 2005 13:45 GMT
It will work if your XML is as follows instead of ur XSLT

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<MyRawHTML>
<![CDATA[<H1>Hello, world!</H1>]]>
</MyRawHTML>

Can you get your XML in this format?
If not - then we can look @ some other Solution.
----------------------------------------------------------------------

> Hi
> What I need to do is to take the following XML (or some variant of it):
[quoted text clipped - 45 lines]
>
> Marek
Mekett - 18 Aug 2005 10:46 GMT
I have te same problem as Marek:
I want to use HTML tags in the XML data file, and I want to keep these
tags in the output.

I tried the CDATA all way, and it doesn't work.
This thing with the "node()" doesn't work too.

But it seems good. Maybe some mistake in the example? (not the double
quote)

Plz help me!
Thanks

--
Mekett


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.