display-recipe.xsl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:eat="http://msqr.us/xsd/ieat" xmlns:xweb="http://msqr.us/xsd/jaxb-web"
  4. xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="eat xweb date"
  5. extension-element-prefixes="date">
  6. <xsl:import href="global-variables.xsl"/>
  7. <xsl:template match="eat:recipe" mode="view">
  8. <h1>
  9. <xsl:value-of select="eat:name"/>
  10. </h1>
  11. <div class="recipe-view">
  12. <xsl:apply-templates select="." mode="display-internal"/>
  13. </div>
  14. </xsl:template>
  15. <xsl:template match="eat:recipe" mode="display">
  16. <div class="recipe-view">
  17. <h2>
  18. <xsl:value-of select="eat:name"/>
  19. </h2>
  20. <xsl:apply-templates select="." mode="display-internal"/>
  21. </div>
  22. </xsl:template>
  23. <xsl:template match="eat:recipe" mode="display-internal">
  24. <xsl:if test="eat:image">
  25. <div>
  26. <img alt="{eat:name}" class="recipe">
  27. <xsl:attribute name="src">
  28. <xsl:value-of select="$web-context"/>
  29. <xsl:value-of select="key('appenv','recipe.image.base.url')"/>
  30. <xsl:value-of select="eat:image"/>
  31. </xsl:attribute>
  32. </img>
  33. </div>
  34. </xsl:if>
  35. <p>
  36. <xsl:value-of select="eat:excerpt"/>
  37. </p>
  38. <xsl:if test="string(eat:directions)">
  39. <p>
  40. <xsl:value-of select="eat:directions"/>
  41. </p>
  42. </xsl:if>
  43. <xsl:if test="string(eat:source)">
  44. <p>
  45. <b><xsl:value-of select="key('i18n','recipe.source.displayName')"/>:</b>
  46. <xsl:text> </xsl:text>
  47. <xsl:apply-templates select="eat:source"/>
  48. </p>
  49. </xsl:if>
  50. <table class="view">
  51. <tr>
  52. <th><xsl:value-of select="key('i18n','recipe.base.displayName')"/>:</th>
  53. <td>
  54. <xsl:apply-templates select="eat:base"/>
  55. </td>
  56. <th><xsl:value-of select="key('i18n','recipe.prepTime.displayName')"/>:</th>
  57. <td>
  58. <xsl:apply-templates select="eat:prep-time"/>
  59. </td>
  60. </tr>
  61. <tr>
  62. <th><xsl:value-of select="key('i18n','recipe.ethnicity.displayName')"/>:</th>
  63. <td>
  64. <xsl:apply-templates select="eat:ethnicity"/>
  65. </td>
  66. <th><xsl:value-of select="key('i18n','recipe.difficulty.displayName')"/>:</th>
  67. <td>
  68. <xsl:apply-templates select="eat:difficulty"/>
  69. </td>
  70. </tr>
  71. <tr>
  72. <th><xsl:value-of select="key('i18n','recipe.course.displayName')"/>:</th>
  73. <td>
  74. <xsl:apply-templates select="eat:course"/>
  75. </td>
  76. <th><xsl:value-of select="key('i18n','recipe.servings.displayName')"/>:</th>
  77. <td>
  78. <xsl:value-of select="@servingSize"/>
  79. </td>
  80. </tr>
  81. </table>
  82. <div class="viewLabel">
  83. <xsl:value-of select="key('i18n','recipe.ingredients.displayName')"/>: </div>
  84. <table class="view">
  85. <xsl:choose>
  86. <xsl:when test="../@mode = 'converted'">
  87. <xsl:apply-templates select="eat:ingredient" mode="converted"/>
  88. </xsl:when>
  89. <xsl:otherwise>
  90. <xsl:apply-templates select="eat:ingredient" mode="display"/>
  91. </xsl:otherwise>
  92. </xsl:choose>
  93. </table>
  94. <xsl:if test="eat:step">
  95. <div class="viewLabel">
  96. <xsl:value-of select="key('i18n','recipe.steps.displayName')"/>: </div>
  97. <div class="viewBox">
  98. <ol>
  99. <xsl:apply-templates select="eat:step" mode="display"/>
  100. </ol>
  101. </div>
  102. </xsl:if>
  103. <br style="clear: both;"/>
  104. <xsl:if test="@createdDate">
  105. <div class="recipe-footer">
  106. <xsl:value-of select="key('i18n','created.on')"/>
  107. <xsl:text> </xsl:text>
  108. <xsl:value-of select="date:format-date(string(@createdDate),'d MMM yyyy')"/>
  109. <xsl:if test="eat:owner/@login">
  110. <xsl:text> </xsl:text>
  111. <xsl:value-of select="key('i18n','by')"/>
  112. <xsl:text> </xsl:text>
  113. <xsl:choose>
  114. <xsl:when test="$acting-user/../@admin = 'true'">
  115. <a href="{$web-context}/user.do?userId={eat:owner/@userId}"
  116. rel="popup|600|400|0|1">
  117. <xsl:value-of select="eat:owner/@login"/>
  118. </a>
  119. </xsl:when>
  120. <xsl:otherwise>
  121. <xsl:value-of select="eat:owner/@login"/>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. <xsl:if test="$acting-user">
  125. <!-- handy link to search for all recipes creatd by a user -->
  126. <a title="{key('i18n','link.quick.searchowner.title')}"
  127. href="{$web-context}/search.do?mode=advanced&amp;criteria.advanced[0].type=3&amp;criteria.advanced[0].op=1&amp;criteria.advanced[0].query={eat:owner/@login}">
  128. <img class="quicklink" width="8" height="9"
  129. src="{$web-context}/img/link-r.png"
  130. alt="{key('i18n','link.quick.searchowner')}"/>
  131. </a>
  132. </xsl:if>
  133. </xsl:if>
  134. </div>
  135. </xsl:if>
  136. </xsl:template>
  137. <xsl:template match="eat:recipe/eat:step" mode="display">
  138. <li>
  139. <xsl:value-of select="."/>
  140. </li>
  141. </xsl:template>
  142. <xsl:template match="eat:recipe/eat:ingredient" mode="converted">
  143. <xsl:variable name="system" select="../eat:system/@systemId"/>
  144. <xsl:variable name="mass" select="eat:unit/@mass"/>
  145. <tr>
  146. <xsl:choose>
  147. <xsl:when
  148. test="not(eat:unit) or ($system = 1 and eat:unit/@toUS = 0) or
  149. ($system = 2 and eat:unit/@toMetric = 0)">
  150. <!-- no conversion necessary -->
  151. <td>
  152. <xsl:call-template name="ingredient-quantity">
  153. <xsl:with-param name="quantity" select="@quantity"/>
  154. </xsl:call-template>
  155. </td>
  156. <td>
  157. <xsl:apply-templates select="eat:unit"/>
  158. </td>
  159. </xsl:when>
  160. <xsl:when test="$mass = 'true' and $system = 1">
  161. <!-- ok, dealing with US ounces: if over 16 oz convert to pounds -->
  162. <xsl:choose>
  163. <xsl:when test="@quantity &lt; 16">
  164. <td>
  165. <xsl:call-template name="ingredient-quantity">
  166. <xsl:with-param name="quantity" select="@quantity"/>
  167. </xsl:call-template>
  168. </td>
  169. <td>
  170. <xsl:call-template name="ingredient-unit">
  171. <xsl:with-param name="quantity" select="@quantity"/>
  172. <xsl:with-param name="abbreviation" select="'oz'"/>
  173. </xsl:call-template>
  174. </td>
  175. </xsl:when>
  176. <xsl:otherwise>
  177. <td>
  178. <xsl:call-template name="ingredient-quantity">
  179. <xsl:with-param name="quantity" select="@quantity div 16.0"/>
  180. </xsl:call-template>
  181. </td>
  182. <td>
  183. <xsl:call-template name="ingredient-unit">
  184. <xsl:with-param name="quantity" select="@quantity div 16.0"/>
  185. <xsl:with-param name="abbreviation" select="'lb'"/>
  186. </xsl:call-template>
  187. </td>
  188. </xsl:otherwise>
  189. </xsl:choose>
  190. </xsl:when>
  191. <xsl:when test="$mass = 'true' and $system = 2">
  192. <!-- ok, dealing with metric grams -->
  193. <xsl:choose>
  194. <xsl:when test="@quantity &lt; 1">
  195. <!-- convert to milligrams -->
  196. <td>
  197. <xsl:call-template name="ingredient-quantity">
  198. <xsl:with-param name="quantity" select="@quantity * 1000"/>
  199. </xsl:call-template>
  200. </td>
  201. <td>
  202. <xsl:call-template name="ingredient-unit">
  203. <xsl:with-param name="quantity" select="@quantity * 1000"/>
  204. <xsl:with-param name="abbreviation" select="'mg'"/>
  205. </xsl:call-template>
  206. </td>
  207. </xsl:when>
  208. <xsl:when test="@quantity &lt; 1000000">
  209. <!-- keep as grams -->
  210. <td>
  211. <xsl:call-template name="ingredient-quantity">
  212. <xsl:with-param name="quantity" select="@quantity"/>
  213. </xsl:call-template>
  214. </td>
  215. <td>
  216. <xsl:call-template name="ingredient-unit">
  217. <xsl:with-param name="quantity" select="@quantity"/>
  218. <xsl:with-param name="abbreviation" select="'g'"/>
  219. </xsl:call-template>
  220. </td>
  221. </xsl:when>
  222. <xsl:otherwise>
  223. <!-- convert to kilograms -->
  224. <td>
  225. <xsl:call-template name="ingredient-quantity">
  226. <xsl:with-param name="quantity" select="@quantity div 1000000.0"
  227. />
  228. </xsl:call-template>
  229. </td>
  230. <td>
  231. <xsl:call-template name="ingredient-unit">
  232. <xsl:with-param name="quantity" select="@quantity div 1000000.0"/>
  233. <xsl:with-param name="abbreviation" select="'kg'"/>
  234. </xsl:call-template>
  235. </td>
  236. </xsl:otherwise>
  237. </xsl:choose>
  238. </xsl:when>
  239. <xsl:when test="$mass = 'false' and $system = 1">
  240. <!-- ok, dealing with US teaspoons -->
  241. <xsl:choose>
  242. <xsl:when test="@quantity &lt; 3">
  243. <!-- keep as teaspoons -->
  244. <td>
  245. <xsl:call-template name="ingredient-quantity">
  246. <xsl:with-param name="quantity" select="@quantity"/>
  247. </xsl:call-template>
  248. </td>
  249. <td>
  250. <xsl:call-template name="ingredient-unit">
  251. <xsl:with-param name="quantity" select="@quantity"/>
  252. <xsl:with-param name="abbreviation" select="'t'"/>
  253. </xsl:call-template>
  254. </td>
  255. </xsl:when>
  256. <xsl:when test="@quantity &lt; 12">
  257. <!-- convert to tablespoons -->
  258. <td>
  259. <xsl:call-template name="ingredient-quantity">
  260. <xsl:with-param name="quantity" select="@quantity div 3.0"/>
  261. </xsl:call-template>
  262. </td>
  263. <td>
  264. <xsl:call-template name="ingredient-unit">
  265. <xsl:with-param name="quantity" select="@quantity div 3.0"/>
  266. <xsl:with-param name="abbreviation" select="'T'"/>
  267. </xsl:call-template>
  268. </td>
  269. </xsl:when>
  270. <xsl:when test="@quantity &lt; 768">
  271. <!-- convert to cups -->
  272. <td>
  273. <xsl:call-template name="ingredient-quantity">
  274. <xsl:with-param name="quantity" select="@quantity div 48.0"/>
  275. </xsl:call-template>
  276. </td>
  277. <td>
  278. <xsl:call-template name="ingredient-unit">
  279. <xsl:with-param name="quantity" select="@quantity div 48.0"/>
  280. <xsl:with-param name="abbreviation" select="'c'"/>
  281. </xsl:call-template>
  282. </td>
  283. </xsl:when>
  284. <xsl:otherwise>
  285. <!-- convert to gallons + fl oz -->
  286. <xsl:variable name="gallons" select="floor(@quantity div 768.0)"/>
  287. <xsl:variable name="ounces" select="@quantity mod 768"/>
  288. <xsl:comment> gals = <xsl:value-of select="$gallons"/> tsp =
  289. <xsl:value-of select="$ounces"/>
  290. </xsl:comment>
  291. <td colspan="2">
  292. <xsl:call-template name="ingredient-quantity">
  293. <xsl:with-param name="quantity" select="$gallons"/>
  294. </xsl:call-template>
  295. <xsl:text> </xsl:text>
  296. <xsl:call-template name="ingredient-unit">
  297. <xsl:with-param name="quantity" select="$gallons"/>
  298. <xsl:with-param name="abbreviation" select="'gal'"/>
  299. </xsl:call-template>
  300. <xsl:if test="$ounces &gt; 0">
  301. <xsl:text>, </xsl:text>
  302. <xsl:call-template name="ingredient-quantity">
  303. <xsl:with-param name="quantity" select="$ounces div 16.0"/>
  304. </xsl:call-template>
  305. <xsl:text> </xsl:text>
  306. <xsl:call-template name="ingredient-unit">
  307. <xsl:with-param name="quantity" select="$ounces div 16.0"/>
  308. <xsl:with-param name="abbreviation" select="'fl.oz'"/>
  309. </xsl:call-template>
  310. </xsl:if>
  311. </td>
  312. </xsl:otherwise>
  313. </xsl:choose>
  314. </xsl:when>
  315. <xsl:when test="$mass = 'false' and $system = 2">
  316. <!-- ok, dealing with metric milliliters -->
  317. <xsl:choose>
  318. <xsl:when test="@quantity &lt; 1000">
  319. <!-- keep as milliliters -->
  320. <td>
  321. <xsl:call-template name="ingredient-quantity">
  322. <xsl:with-param name="quantity" select="@quantity"/>
  323. </xsl:call-template>
  324. </td>
  325. <td>
  326. <xsl:call-template name="ingredient-unit">
  327. <xsl:with-param name="quantity" select="@quantity"/>
  328. <xsl:with-param name="abbreviation" select="'ml'"/>
  329. </xsl:call-template>
  330. </td>
  331. </xsl:when>
  332. <xsl:otherwise>
  333. <!-- convert to liters -->
  334. <td>
  335. <xsl:call-template name="ingredient-quantity">
  336. <xsl:with-param name="quantity" select="@quantity div 1000.0"/>
  337. </xsl:call-template>
  338. </td>
  339. <td>
  340. <xsl:call-template name="ingredient-unit">
  341. <xsl:with-param name="quantity" select="@quantity div 1000.0"/>
  342. <xsl:with-param name="abbreviation" select="'L'"/>
  343. </xsl:call-template>
  344. </td>
  345. </xsl:otherwise>
  346. </xsl:choose>
  347. </xsl:when>
  348. <xsl:otherwise>
  349. <xsl:comment> ack! </xsl:comment>
  350. <!-- ack! -->
  351. </xsl:otherwise>
  352. </xsl:choose>
  353. <td>
  354. <xsl:text> </xsl:text>
  355. <xsl:apply-templates select="eat:ingredient"/>
  356. <xsl:apply-templates select="eat:recipe"/>
  357. <xsl:if test="string-length(@qualifier) &gt; 0">
  358. <xsl:text> - </xsl:text>
  359. <i>
  360. <xsl:value-of select="@qualifier"/>
  361. </i>
  362. </xsl:if>
  363. </td>
  364. </tr>
  365. </xsl:template>
  366. <xsl:template match="eat:recipe/eat:ingredient" mode="display">
  367. <tr>
  368. <td>
  369. <xsl:call-template name="ingredient-quantity">
  370. <xsl:with-param name="quantity" select="@quantity"/>
  371. </xsl:call-template>
  372. </td>
  373. <td>
  374. <xsl:text> </xsl:text>
  375. <xsl:apply-templates select="eat:unit"/>
  376. <xsl:text> </xsl:text>
  377. <xsl:apply-templates select="eat:ingredient"/>
  378. <xsl:apply-templates select="eat:recipe"/>
  379. <xsl:if test="string-length(@qualifier) &gt; 0">
  380. <xsl:text> - </xsl:text>
  381. <i>
  382. <xsl:value-of select="@qualifier"/>
  383. </i>
  384. </xsl:if>
  385. </td>
  386. </tr>
  387. </xsl:template>
  388. <xsl:template match="eat:base">
  389. <xsl:choose>
  390. <xsl:when test="$aux/eat:ui/eat:base">
  391. <xsl:variable name="base-id" select="@baseId"/>
  392. <xsl:value-of select="$aux/eat:ui/eat:base[@baseId = $base-id]"/>
  393. </xsl:when>
  394. <xsl:otherwise>
  395. <xsl:value-of select="."/>
  396. </xsl:otherwise>
  397. </xsl:choose>
  398. </xsl:template>
  399. <xsl:template match="eat:course">
  400. <xsl:variable name="display-key">
  401. <xsl:text>course.</xsl:text>
  402. <xsl:choose>
  403. <xsl:when test="$aux/eat:ui/eat:course">
  404. <xsl:variable name="course-id" select="@courseId"/>
  405. <xsl:value-of
  406. select="translate($aux/eat:ui/eat:course[@courseId = $course-id],' ','')"/>
  407. </xsl:when>
  408. <xsl:otherwise>
  409. <xsl:value-of select="translate(string(.),' ','')"/>
  410. </xsl:otherwise>
  411. </xsl:choose>
  412. </xsl:variable>
  413. <xsl:choose>
  414. <xsl:when test="key('i18n',$display-key)">
  415. <xsl:value-of select="key('i18n',$display-key)"/>
  416. </xsl:when>
  417. <xsl:otherwise>
  418. <xsl:value-of select="."/>
  419. </xsl:otherwise>
  420. </xsl:choose>
  421. </xsl:template>
  422. <xsl:template match="eat:difficulty">
  423. <xsl:choose>
  424. <xsl:when test="$aux/eat:ui/eat:difficulty">
  425. <xsl:variable name="difficulty-id" select="@difficultyId"/>
  426. <xsl:value-of select="$aux/eat:ui/eat:difficulty[@difficultyId = $difficulty-id]"/>
  427. </xsl:when>
  428. <xsl:otherwise>
  429. <xsl:value-of select="."/>
  430. </xsl:otherwise>
  431. </xsl:choose>
  432. </xsl:template>
  433. <xsl:template match="eat:ethnicity">
  434. <xsl:choose>
  435. <xsl:when test="$aux/eat:ui/eat:ethnicity">
  436. <xsl:variable name="ethnicity-id" select="@ethnicityId"/>
  437. <xsl:value-of select="$aux/eat:ui/eat:ethnicity[@ethnicityId = $ethnicity-id]"/>
  438. </xsl:when>
  439. <xsl:otherwise>
  440. <xsl:value-of select="."/>
  441. </xsl:otherwise>
  442. </xsl:choose>
  443. </xsl:template>
  444. <xsl:template match="eat:prep-time">
  445. <xsl:choose>
  446. <xsl:when test="$aux/eat:ui/eat:prep-time">
  447. <xsl:variable name="preptime-id" select="@prepTimeId"/>
  448. <xsl:value-of select="$aux/eat:ui/eat:prep-time[@prepTimeId = $preptime-id]"/>
  449. </xsl:when>
  450. <xsl:otherwise>
  451. <xsl:value-of select="."/>
  452. </xsl:otherwise>
  453. </xsl:choose>
  454. </xsl:template>
  455. <xsl:template match="eat:unit">
  456. <xsl:variable name="unit-key">
  457. <xsl:text>unit.</xsl:text>
  458. <xsl:choose>
  459. <xsl:when test="$aux/eat:ui/eat:unit">
  460. <xsl:variable name="unit-id" select="@unitId"/>
  461. <xsl:value-of
  462. select="translate($aux/eat:ui/eat:unit[@unitId = $unit-id]/@abbreviation,' ','')"
  463. />
  464. </xsl:when>
  465. <xsl:otherwise>
  466. <xsl:value-of select="translate(@abbreviation,' ','')"/>
  467. </xsl:otherwise>
  468. </xsl:choose>
  469. <xsl:if test="../@quantity &gt; 1">
  470. <xsl:text>.plural</xsl:text>
  471. </xsl:if>
  472. </xsl:variable>
  473. <xsl:choose>
  474. <xsl:when test="key('i18n',$unit-key)">
  475. <xsl:value-of select="key('i18n',$unit-key)"/>
  476. </xsl:when>
  477. <xsl:otherwise>
  478. <xsl:value-of select="."/>
  479. </xsl:otherwise>
  480. </xsl:choose>
  481. </xsl:template>
  482. <xsl:template match="eat:ingredient">
  483. <xsl:choose>
  484. <xsl:when test="$aux/eat:ui/eat:ingredient">
  485. <xsl:variable name="ingredient-id" select="@ingredientId"/>
  486. <xsl:value-of
  487. select="$aux/eat:ui/eat:ingredient[@ingredientId = $ingredient-id]/eat:name"/>
  488. </xsl:when>
  489. <xsl:otherwise>
  490. <xsl:value-of select="eat:name"/>
  491. </xsl:otherwise>
  492. </xsl:choose>
  493. </xsl:template>
  494. <xsl:template match="eat:ingredient/eat:recipe">
  495. <a href="{$web-context}/recipe.do?recipeId={@recipeId}">
  496. <xsl:choose>
  497. <xsl:when test="string-length(eat:name) = 0">
  498. <xsl:variable name="recipe-id" select="@recipeId"/>
  499. <xsl:value-of select="$aux/eat:ui/eat:recipe[@recipeId = $recipe-id]/eat:name"/>
  500. </xsl:when>
  501. <xsl:otherwise>
  502. <xsl:value-of select="eat:name"/>
  503. </xsl:otherwise>
  504. </xsl:choose>
  505. </a>
  506. </xsl:template>
  507. <xsl:template name="ingredient-quantity">
  508. <xsl:param name="quantity"/>
  509. <xsl:variable name="whole">
  510. <xsl:choose>
  511. <xsl:when test="contains($quantity,'.')">
  512. <xsl:value-of select="substring-before($quantity,'.')"/>
  513. </xsl:when>
  514. <xsl:otherwise>
  515. <xsl:value-of select="$quantity"/>
  516. </xsl:otherwise>
  517. </xsl:choose>
  518. </xsl:variable>
  519. <xsl:variable name="frac" select="$quantity - $whole"/>
  520. <!--
  521. <xsl:comment>
  522. whole = <xsl:value-of select="$whole"/>
  523. frac = <xsl:value-of select="$frac"/>
  524. </xsl:comment>
  525. -->
  526. <xsl:choose>
  527. <xsl:when test="$frac = 0">
  528. <xsl:value-of select="$whole"/>
  529. </xsl:when>
  530. <xsl:otherwise>
  531. <xsl:if test="not($whole = 0)">
  532. <xsl:value-of select="$whole"/>
  533. <xsl:text> </xsl:text>
  534. </xsl:if>
  535. <xsl:choose>
  536. <xsl:when test="$frac = .75">
  537. <xsl:text>&#x00BE;</xsl:text>
  538. </xsl:when>
  539. <xsl:when
  540. test="(format-number($frac,'.00') = '.67') or (format-number($frac,'.00') = '.66')">
  541. <xsl:text>&#x2154;</xsl:text>
  542. </xsl:when>
  543. <xsl:when test="$frac = .5">
  544. <xsl:text>&#x00BD;</xsl:text>
  545. </xsl:when>
  546. <xsl:when test="format-number($frac,'.00') = '.33'">
  547. <xsl:text>&#x2153;</xsl:text>
  548. </xsl:when>
  549. <xsl:when test="$frac = .25">
  550. <xsl:text>&#x00BC;</xsl:text>
  551. </xsl:when>
  552. <xsl:when test="floor($frac * 8) = $frac * 8">
  553. <xsl:value-of select="$frac * 8"/>
  554. <xsl:text>/8</xsl:text>
  555. </xsl:when>
  556. <xsl:when test="floor($frac * 16) = $frac * 16">
  557. <xsl:value-of select="$frac * 16"/>
  558. <xsl:text>/16</xsl:text>
  559. </xsl:when>
  560. <xsl:when test="floor($frac * 32) = $frac * 32">
  561. <xsl:value-of select="$frac * 32"/>
  562. <xsl:text>/32</xsl:text>
  563. </xsl:when>
  564. <xsl:otherwise>
  565. <xsl:value-of select="format-number($frac,'.00#')"/>
  566. </xsl:otherwise>
  567. </xsl:choose>
  568. </xsl:otherwise>
  569. </xsl:choose>
  570. </xsl:template>
  571. <xsl:template name="ingredient-unit">
  572. <xsl:param name="quantity"/>
  573. <xsl:param name="abbreviation"/>
  574. <xsl:variable name="unit-key">
  575. <xsl:text>unit.</xsl:text>
  576. <xsl:choose>
  577. <xsl:when test="$abbreviation">
  578. <xsl:value-of select="translate($abbreviation,' ','')"/>
  579. </xsl:when>
  580. <xsl:otherwise>
  581. <xsl:variable name="unit-id" select="@unitId"/>
  582. <xsl:value-of
  583. select="translate($aux/eat:ui/eat:unit[@unitId = $unit-id]/@abbreviation,' ','')"
  584. />
  585. </xsl:otherwise>
  586. </xsl:choose>
  587. <xsl:if test="$quantity &gt; 1">
  588. <xsl:text>.plural</xsl:text>
  589. </xsl:if>
  590. </xsl:variable>
  591. <xsl:value-of select="key('i18n',$unit-key)"/>
  592. </xsl:template>
  593. </xsl:stylesheet>