SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: XML and XSL
-
Apr 8, 2002, 03:14 #1
XML and XSL
I am using XSL for an XML document and it isnt working. my XSL document:
PHP Code:xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<script language="JavaScript"><xsl:comment><![CDATA[
function sort(key) {
var s = document.XSLDocument.selectNodes("*/xsl:template[@match='products']//xsl:apply-templats/@order-by");
for (var a = s.nextNode(); a != null; a = s.nextNode()) {
a.value = key;
}
var d = document.XMLDocument.selectNodes("test_product_info/products");
products.innerHTML = d.transformNode(document.XMLDocument);
}
]]></xsl:comment></script>
</head>
<body>
<table border="0" bgcolor="#aaaaaa">
<tr>
<td colspan="2">
<div id="products">
<xsl:apply-templates select="product_info/products"/>
</div>
</td>
</tr>
<tr>
<td align="center">
<a href="javascript:sort('price_per_unit')">Sort by price</a>
</td>
<td>
<a href="javascript:sort('name')">Sort by name</a>
</td>
</tr>
</table>
<p/>
</body>
</html>
</xsl:template>
<xsl:template match="products">
<table cellspacing="0" border="0" bgcolor="#aaaaaa">
<xsl:apply-templates select="item" order-by="name"/>
</table>
</xsl:template>
<xsl:template match="item">
<tr>
<td><b><xsl:value-of select="name"/></b></td>
<td>..........</td>
<td valign="bottom"><xsl:value-of select="price_per_unit"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
PHP Code:<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="sort.xsl"?>
<product_info xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional">
<products>
<item>
<name>Product 1</name>
<price_per_unit currency="USD">6.50</price_per_unit>
</item>
<item>
<name>Product 2</name>
<price_per_unit currency="USD">5.00</price_per_unit>
</item>
<item>
<name>Product 3</name>
<price_per_unit currency="CD">8.25</price_per_unit>
</item>
</products>
</test_product_info>
-
Apr 8, 2002, 06:31 #2
- Join Date
- Nov 1999
- Location
- Mechanicsburg, PA
- Posts
- 7,294
- Mentioned
- 123 Post(s)
- Tagged
- 1 Thread(s)
It would help to know what's not working. I'm not great at XML/XSL, but I can figure it out quicker if I know what I'm looking for...
Dave Maxwell - Manage Your Site Team Leader
My favorite YouTube Video! | Star Wars, Dr Suess Style
Learn how to be ready for The Forums' Move to Discourse
-
Apr 8, 2002, 11:41 #3
- Join Date
- Sep 1999
- Location
- Singapore
- Posts
- 854
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
One problem I could see is that your element <product_info> is closed with </test_product_info>, but I don't think that's your major problem?
-
Apr 8, 2002, 11:45 #4
Sorry I forgot to post the error.
A CDATA section was not closed. Error processing resource 'file:///C:/XML/sort.xsl'. Line 5, Position 63
<script language="JavaScript"><xsl:comment><![CDATA[
I also changed <product_info></product_info> and its still not working
Bookmarks