473,395 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Generating html out of xml using xslt

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"
xmlns:xsl="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
Jul 20 '05 #1
3 1347
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

Jul 20 '05 #2
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.
Jul 20 '05 #3
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"
xmlns:xsl="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"

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter Caspers | last post by:
Hi, I have an XML-file out of which I generate a HTML-file with an XSL. It seems that it is only possible to generate one single HTML-file and not multiple files e.g. in order to distribute...
3
by: Steve Dussinger | last post by:
Hi All: I am attempting to use an XSL stylesheet to take data from an existing DOM document, and place it into a different existing DOM document. The problem I'm having is that I get the...
4
by: Tristan Miller | last post by:
Greetings. I would like to produce a static multilingual website in XHTML. Is it possible to specify each web page in its own XML file, but have all of the translations encapsulated in that one...
2
by: Andy Dingley | last post by:
I have some (somewhat ragged) HTML, and I wish to pre-process it with XSLT before putting it back onto the server. Throughout this HTML are many character entity references, such as "&ecaute;". ...
5
by: shauldar | last post by:
Is there a way (tool, hack...) to create an XSL:FO from an XSLT + XML files? My motivation is that we want to use a tool to design reports, and from that "design" generate both HTML (via XSLT)...
1
by: Andy Fish | last post by:
Hi, In my aspx web application, I am generating a list of items in a menu down the left-hand side. Different items in the list may have different controls in, and this is data-driven at runtime....
3
by: crc128 | last post by:
Hi, I'm looking at using XML and XSLT with apache cocoon to automatically generate html files for a site. the problem I'm having is that I want one of the pages to display a google map, but the...
7
by: Dag Sunde | last post by:
I want to use the format-number function to output a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a...
3
by: Andy Dingley | last post by:
>From a thread over in c.i.w.a.h "RFC: From XHTML to HTML via XSLT" http://groups.google.co.uk/group/comp.infosystems.www.authoring.html/msg/f112c230061ffe86 As is well-known, the XSLT HTML...
2
by: orsula | last post by:
Hi all, I would like to generate xml from a structure, e.g.: Dictionary <key, valueArraymyDict; Into : <myDict> <key>key</key> <valueArray> <value>1</value> <value>2</value>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.