-
Notifications
You must be signed in to change notification settings - Fork 2
/
Scenario1.xsl
58 lines (55 loc) · 2.84 KB
/
Scenario1.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--This line below was necessary when using xsltransform.net-->
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<!--Retrieving all recipes that have low sugar content (below 5g) in the nutrition info
and sort them from lowest to highest-->
<!--TEMPLATE 1
We match to the root of the XML source file.-->
<xsl:template match="/">
<!--We insert html elements to render the output more visually appealing-->
<html>
<head>
<title>Low Glycemic Recipes</title>
<!--This defines the structure of the table
We have a light-grey fine border around each cell
We align the text to the elft
We define padding i.e. space between the content and the border
We set te header cells to a different color from the rest-->
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<!--We count all recipes that have an idref sugar with a nutr_value of less than 5-->
<body>
<h2>Here is the list of <xsl:value-of select="count(//recipes/recipe[information/value_information/nutrition/nutr_value[@idref='sugar' and . < 5]])"/> low-sugar recipes</h2>
<table>
<tr>
<th>Recipe Title</th>
<th>Sugar Content (g)</th>
</tr>
<!--For each recipe that has an idref sugar with a nutr_value of less than 5, we sort them from lowest sugar content to higher
We retrieve the recipe name and the sugar level -->
<xsl:for-each select="//recipes/recipe[information/value_information/nutrition/nutr_value[@idref='sugar' and . < 5]]">
<xsl:sort select="information/value_information/nutrition/nutr_value[@idref='sugar']" data-type="number" order="ascending"/>
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="information/value_information/nutrition/nutr_value[@idref='sugar']"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>