Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Generating html out of xml using xslt

Reply
Thread Tools

Generating html out of xml using xslt

 
 
Brent
Guest
Posts: n/a
 
      03-17-2005
Hi All,

I'm trying to transform an xml document into an html doc, with an xsl
doc. It's a simple document, shown below:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>


The xsl stylesheet looks like this:


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>



I've tried using two processors: Cooktop and Saxon 8.3 B, but neither of
them produce the right html output. The output looks like this:


<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
</table>
</body>
</html>


I've tried it without the for-each loop, but it doesn't seem to be
grabbing the data.
Is there something I'm missing?


Thanks for any hints!

Brent
 
Reply With Quote
 
 
 
 
grouch
Guest
Posts: n/a
 
      03-17-2005
Brent wrote:

>
> I've tried using two processors: Cooktop and Saxon 8.3 B, but neither

of
> them produce the right html output. The output looks like this:
>
>
> <html>
> <body>
> <h2>My CD Collection</h2>
> <table border="1">
> <tr bgcolor="#9acd32">
> <th align="left">Title</th>
> <th align="left">Artist</th>
> </tr>
> </table>
> </body>
> </html>
>



Hmm,

I've tried it using XmlStarlet (http://xmlstar.sourceforge.net/)
with your stylesheet and XML and it worked fine.

$ xml tr -E catalog.xml
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
</tr>
</table>
</body>
</html>

Since you are referencing to your stylesheet from XML,
as a test you could just open your XML in a browser and see.

--MG

 
Reply With Quote
 
 
 
 
Malte
Guest
Posts: n/a
 
      03-17-2005
Brent wrote:

>
> I've tried using two processors: Cooktop and Saxon 8.3 B, but neither of
> them produce the right html output. The output looks like this:


I ran it though oxygenXml and it looks fine. Oxygen uses Xalan, I believe.
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      03-22-2005
Brent wrote:

> Hi All,
>
> I'm trying to transform an xml document into an html doc, with an xsl
> doc. It's a simple document, shown below:

[snip]
> The xsl stylesheet looks like this:

[snip]
> I've tried using two processors: Cooktop and Saxon 8.3 B, but neither of
> them produce the right html output. The output looks like this:

[snip]
> I've tried it without the for-each loop, but it doesn't seem to be
> grabbing the data.
> Is there something I'm missing?


It works fine using Saxon b8-0 here.

<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
</tr>
</table>
</body>
</html>

However...you may find it easier to use templates rather than for-each:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="cd">
<tr>
<td>
<xsl:apply-templates select="title"/>
</td>
<td>
<xsl:apply-templates select="artist"/>
</td>
</tr>
</xsl:template>

</xsl:stylesheet>

///Peter
--
sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
&;top"

 
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
Generating XSL:FO from XSLT (and XML) shauldar@gmail.com XML 6 11-07-2011 09:01 PM
dynamically generating html vs using html scaffolding? Faisal Vali Javascript 10 06-21-2008 04:31 PM
Generating HTML from XSLT using <xsl:copy> Andy Dingley XML 3 03-27-2007 02:45 PM
XML, XSLT and generating ID's rob.guitar.rob@gmail.com XML 2 07-29-2005 09:41 PM
problem generating html table via xslt T. Sander XML 2 08-20-2004 05:07 PM



Advertisments