File: recipeToHTML.xsl

package info (click to toggle)
anymeal 0.30-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,656 kB
  • ctags: 1,292
  • sloc: sh: 12,281; cpp: 11,600; perl: 2,730; lex: 1,098; makefile: 117
file content (132 lines) | stat: -rw-r--r-- 4,718 bytes parent folder | download
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="html" indent="yes" version="4.0" encoding="UTF-8"/>

  <xsl:param name="lfile">dictionary.xml</xsl:param>
  <xsl:param name="lname">en</xsl:param>

  <xsl:template match="/insert|/sqlout">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>
          <xsl:value-of select="document($lfile)/dictionary/entry[@text='Cookbook']"/>
        </title>
        <meta name="generator" content="AnyMeal"/>
      </head>
      <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
        <xsl:apply-templates select="recipe"/>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="recipe">
    <h1>
      <xsl:value-of select="document($lfile)/dictionary/entry[@text='Cookbook']"/>
      <xsl:text>: </xsl:text>
      <xsl:value-of select="title"/>
    </h1>
    <table align="right" style="text-align: left; width: 300px; background-color: rgb(255, 255, 221);">

      <tr>
        <th colspan="2" style="text-align: center; background-color: #DDDDBB">
          <xsl:value-of select="title"/>
        </th>
      </tr>
      <!-- <tr>
        <td colspan="2" style="text-align: center">
          <img src="..." alt="" width="300" longdesc="..."/>
        </td>
      </tr> -->
      <tr>
        <td>
          <xsl:value-of select="document($lfile)/dictionary/entry[@text='Categories']"/>
          <xsl:text>: </xsl:text>
        </td>
        <td>
          <xsl:for-each select="categories/category">
            <!-- a href? -->
            <xsl:value-of select="."/>
            <xsl:if test="not(position()=last())">, </xsl:if>          
          </xsl:for-each>
        </td>
      </tr>
      <tr>
        <td>
          <xsl:value-of select="document($lfile)/dictionary/entry[@text='Yield']"/>
          <xsl:text>: </xsl:text>
        </td>
        <td>
          <xsl:value-of select="servings/amount"/>
          <xsl:text> </xsl:text>
          <xsl:value-of select="servings/unit"/>
        </td>
      </tr>
    </table>
    <h2>
      <xsl:value-of select="document($lfile)/dictionary/entry[@text='Ingredients']"/>
    </h2>
    <xsl:for-each select="ingredients/section">
      <xsl:variable name="section" select="column[position()=1]"/>
      <xsl:if test="title">
        <h3>
          <xsl:value-of select="title"/>
        </h3>
      </xsl:if>
      <ul>
        <xsl:for-each select="ingredient">
          <li>
            <xsl:if test="amount">
              <xsl:choose>
                <xsl:when test="amount/float">
                  <xsl:value-of select="amount/float"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <xsl:when test="amount/fraction/nominator >= amount/fraction/denominator">
                      <xsl:value-of select="floor(amount/fraction/nominator div amount/fraction/denominator)"/>
                      <xsl:if test="amount/fraction/nominator mod amount/fraction/denominator > 0">
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="amount/fraction/nominator mod amount/fraction/denominator"/>
                        <xsl:text>/</xsl:text>
                        <xsl:value-of select="amount/fraction/denominator"/>
                      </xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="amount/fraction/nominator"/>
                      <xsl:text>/</xsl:text>
                      <xsl:value-of select="amount/fraction/denominator"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:text> </xsl:text>
            </xsl:if>
            <xsl:if test="unit">
              <xsl:value-of select="unit"/>
              <xsl:text> </xsl:text>
            </xsl:if>
            <xsl:value-of select="name"/>
            <xsl:if test="prep">
              <xsl:text>; </xsl:text>
              <xsl:value-of select="prep"/>
            </xsl:if>
          </li>
        </xsl:for-each>
      </ul>
    </xsl:for-each>
    <h2><xsl:value-of select="document($lfile)/dictionary/entry[@text='Preparation']"/></h2>
    <xsl:for-each select="instructions/section">
      <xsl:if test="title">
        <h3><xsl:value-of select="title"/></h3>
      </xsl:if>
      <xsl:for-each select="par">
        <p>
          <xsl:value-of select="."/>
        </p>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>