babylikesburgh
08-21-2008, 08:58 PM
I'm almost as sure as I can be that I have this xsl doc set up correctly. And, I'm sure I have the xml doc correct, too. All I need help with is determining where I'm going wrong connecting the two. I've Googled "tables in xml stylesheets" and things of the sort, but still I can't find where I'm going wrong. The table header prints out fine (I have the xsl doc saved as an html doc currently so I can "test" it), but that's all I'm getting. I tried href-ing to nutrition.xsl while it was saved to that, too, but it was a no go. So, I think I have everything down, just not how to connect these two. Any suggestions, if only a hint, as to where I'm going wrong? This looks like it should be MUCH easier than I'm making it.. :o I have an idea I shouldn't be using <xsl:for-each select=" = "whitescookie"> in the stylesheet, I've tried a couple other things too that I've found on XML tip sites... ugh... I'm getting frustrated!
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = nutrition.html"?>
<!--Marking up documents-->
<whitescookie>
<serving>1 package</serving>
<calories>260 calories</calories>
<fatcals>100 fat calories</fatcals>
<fat>11 g of fat</fat>
<saturatedfat>2 g of saturated fat</saturatedfat>
<cholesterol>5 mg of cholesterol</cholesterol>
<sodium>210 mg of sodium</sodium>
<carbohydrates>36 g of carbs</carbohydrates>
<fiber>2 g of fiber</fiber>
<sugar>15 g of sugar</sugar>
<protein>5 g of protein</protein>
</whitescookie>
...and the stylesheet "nutrition.html":
<?xml version = "1.0"?>
<!-- XSL Stylesheet -->
<!-- reference XSL style sheet URI -->
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "html" omit-xml-declaration = "no"
doctype-system =
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd"
doctype-public = "-//W3C//DTD XHTML 1.1//EN"/>
<xsl:template match = "/">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Nutritional Information - Grandma White's Cookies</title>
</head>
<body>
<table border = "1" bgcolor = "cream">
<thead>
<tr>
<th>Nutritional Information</th>
</tr>
</thead>
<xsl:for-each select=" = "whitescookie">
<tr>
<td><xsl:value-of select = "@serving"/></td></tr>
<td><xsl:value-of select = "@calories"/></td></tr>
<td><xsl:value-of select = "@fatcals"/></td></tr>
<td><xsl:value-of select = "@saturatedfat"/></td></tr>
<td><xsl:value-of select = "@cholesterol"/></td></tr>
<td><xsl:value-of select = "@sodium"/></td></tr>
<td><xsl:value-of select = "@carbohydrates"/></td></tr>
<td><xsl:value-of select = "@fiber"/></td></tr>
<td><xsl:value-of select = "@sugar"/></td></tr>
<td><xsl:value-of select = "@protein"/></td></tr>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = nutrition.html"?>
<!--Marking up documents-->
<whitescookie>
<serving>1 package</serving>
<calories>260 calories</calories>
<fatcals>100 fat calories</fatcals>
<fat>11 g of fat</fat>
<saturatedfat>2 g of saturated fat</saturatedfat>
<cholesterol>5 mg of cholesterol</cholesterol>
<sodium>210 mg of sodium</sodium>
<carbohydrates>36 g of carbs</carbohydrates>
<fiber>2 g of fiber</fiber>
<sugar>15 g of sugar</sugar>
<protein>5 g of protein</protein>
</whitescookie>
...and the stylesheet "nutrition.html":
<?xml version = "1.0"?>
<!-- XSL Stylesheet -->
<!-- reference XSL style sheet URI -->
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "html" omit-xml-declaration = "no"
doctype-system =
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd"
doctype-public = "-//W3C//DTD XHTML 1.1//EN"/>
<xsl:template match = "/">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Nutritional Information - Grandma White's Cookies</title>
</head>
<body>
<table border = "1" bgcolor = "cream">
<thead>
<tr>
<th>Nutritional Information</th>
</tr>
</thead>
<xsl:for-each select=" = "whitescookie">
<tr>
<td><xsl:value-of select = "@serving"/></td></tr>
<td><xsl:value-of select = "@calories"/></td></tr>
<td><xsl:value-of select = "@fatcals"/></td></tr>
<td><xsl:value-of select = "@saturatedfat"/></td></tr>
<td><xsl:value-of select = "@cholesterol"/></td></tr>
<td><xsl:value-of select = "@sodium"/></td></tr>
<td><xsl:value-of select = "@carbohydrates"/></td></tr>
<td><xsl:value-of select = "@fiber"/></td></tr>
<td><xsl:value-of select = "@sugar"/></td></tr>
<td><xsl:value-of select = "@protein"/></td></tr>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>