Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2006, 07:07 AM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTML Code in XML

Hi all,
I have an XML file as follows:

<?xml version="1.0"?>
<planets>
   <planet>
      <Name>Mercury</Name>
      <info>
         <table>
            <tr>
              <td>Smallest Planet</td>
              <td>Closest to Sun</td>
            </tr>
         </table>
      </info>
   </planet>

   <planet>
       <Name>Earth</Name>
       <info> This is the planet we all live on </info>
   </planet>
</planets>

There is no particular pattern in info field. But whatever is given as the value of info, will be in html.

Is there a way to use XSL and generate the following html code...

<html>
   <head>
      Planets
   </head>
   <body>
      <h1>Mercury</h1>
      <table>
         <tr>
            <td>Smallest Planet</td>
            <td>Closest to Sun</td>
        </tr>
      </table>
      <h1>Earth</h1>
      This is the planet we all live on
   </body>
</html>

Can some body help me with this? I need to get the content/value of <info> as it is (even though it is html) and put it in the resultant html file using XSL.

Thanks,
Neelima
 
Old May 4th, 2006, 07:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's got to be HTML in the form of well-formed XML - you can't have things like <br> without an end tag.

Given that constraint, you can copy it through by using

<xsl:template match="info">
  <xsl:copy-of select="child::node()"/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 4th, 2006, 07:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

And please: don't ask the same question on more than one forum. It means I've just wasted my time replying because you already got a perfectly good answer elsewhere. You're not here to waste people's time.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML code from XML to display using XSL koenige XSLT 6 October 27th, 2008 08:11 AM
Is XML supports transformation of HTML to XML? zeeonline XSLT 1 July 28th, 2006 05:13 PM
XML to HTML shoei78 XSLT 2 June 24th, 2003 08:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.