<?xml version=\"1.0\" encoding=\"utf-8\"?> <product name = \"Grandma White'
ID: 3666307 • Letter: #
Question
<?xml version="1.0" encoding="utf-8"?>
<product name = "Grandma White's Cookies">
<servingsize>1 package</servingsize>
<calories>
<total>260 Calories</total>
<fat>100 Calories</fat>
</calories>
<fat>
<total>11 grams</total>
<saturated>2 grams</saturated>
</fat>
<cholesterol>5 milligrams</cholesterol>
<sodium>210 milligrams</sodium>
<carbohydrates>
<total>36 grams</total>
<fiber>2 grams</fiber>
<sugars>15 grams</sugars>
</carbohydrates>
<protein>5 grams</protein>
</product>
WRITE AN XSL STYLE SHEET FOR FOR THE ABOVE CODE THAT DISPLAYS THE NUTRITIONAL FACTS IN AN HTML5 TABLE. CODE MUST BE ABLE TO BE PLACED DIRECTLY INTO NOTEPAD TO BE USED FOR WEB PROGRAMMING.
Explanation / Answer
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type = "text/xsl" href="nutrition.xsl"?>
<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/xhtml1-strict.dtd"
doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN" />
<xsl:template match = "/">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title><xsl:value-of select = "product/@name"/> </title>
</head>
<body>
<h1><xsl:value-of select = "product/@name"/></h1>
<h2><xsl:value-of select = "product/servingsize"/></h2>
<table border = "1">
<thead>
<tr>
<th>calories</th>
<th>fat</th>
<th>cholesterol</th>
<th>sodium</th>
<th>carbohydrates</th>
<th>protein</th>
</tr>
</thead>
<xsl:for-each select = "product">
<tr>
<td>total: <xsl:value-of select = "calories/total"/></td>
<td>total: <xsl:value-of select = "fat/total"/></td>
<td><xsl:value-of select = "cholesterol"/></td>
<td><xsl:value-of select = "sodium"/></td>
<td>total: <xsl:value-of select = "carbohydrates/total"/></td>
<td><xsl:value-of select = "protein"/></td>
</tr>
</xsl:for-each>
<xsl:for-each select = "product">
<tr>
<td>fat: <xsl:value-of select = "calories/fat"/></td>
<td>saturated: <xsl:value-of select = "fat/saturated"/></td>
<td></td>
<td></td>
<td>fiber: <xsl:value-of select = "carbohydrates/fiber"/></td>
<td></td>
</tr>
</xsl:for-each>
<xsl:for-each select = "product">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>sugars: <xsl:value-of select ="carbohydrates/sugars"/></td>
<td></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.