| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621 |
- <?xml version="1.0"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:eat="http://msqr.us/xsd/ieat" xmlns:xweb="http://msqr.us/xsd/jaxb-web"
- xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="eat xweb date"
- extension-element-prefixes="date">
- <xsl:import href="global-variables.xsl"/>
- <xsl:template match="eat:recipe" mode="view">
- <h1>
- <xsl:value-of select="eat:name"/>
- </h1>
- <div class="recipe-view">
- <xsl:apply-templates select="." mode="display-internal"/>
- </div>
- </xsl:template>
- <xsl:template match="eat:recipe" mode="display">
- <div class="recipe-view">
- <h2>
- <xsl:value-of select="eat:name"/>
- </h2>
- <xsl:apply-templates select="." mode="display-internal"/>
- </div>
- </xsl:template>
- <xsl:template match="eat:recipe" mode="display-internal">
- <xsl:if test="eat:image">
- <div>
- <img alt="{eat:name}" class="recipe">
- <xsl:attribute name="src">
- <xsl:value-of select="$web-context"/>
- <xsl:value-of select="key('appenv','recipe.image.base.url')"/>
- <xsl:value-of select="eat:image"/>
- </xsl:attribute>
- </img>
- </div>
- </xsl:if>
- <p>
- <xsl:value-of select="eat:excerpt"/>
- </p>
- <xsl:if test="string(eat:directions)">
- <p>
- <xsl:value-of select="eat:directions"/>
- </p>
- </xsl:if>
- <xsl:if test="string(eat:source)">
- <p>
- <b><xsl:value-of select="key('i18n','recipe.source.displayName')"/>:</b>
- <xsl:text> </xsl:text>
- <xsl:apply-templates select="eat:source"/>
- </p>
- </xsl:if>
- <table class="view">
- <tr>
- <th><xsl:value-of select="key('i18n','recipe.base.displayName')"/>:</th>
- <td>
- <xsl:apply-templates select="eat:base"/>
- </td>
- <th><xsl:value-of select="key('i18n','recipe.prepTime.displayName')"/>:</th>
- <td>
- <xsl:apply-templates select="eat:prep-time"/>
- </td>
- </tr>
- <tr>
- <th><xsl:value-of select="key('i18n','recipe.ethnicity.displayName')"/>:</th>
- <td>
- <xsl:apply-templates select="eat:ethnicity"/>
- </td>
- <th><xsl:value-of select="key('i18n','recipe.difficulty.displayName')"/>:</th>
- <td>
- <xsl:apply-templates select="eat:difficulty"/>
- </td>
- </tr>
- <tr>
- <th><xsl:value-of select="key('i18n','recipe.course.displayName')"/>:</th>
- <td>
- <xsl:apply-templates select="eat:course"/>
- </td>
- <th><xsl:value-of select="key('i18n','recipe.servings.displayName')"/>:</th>
- <td>
- <xsl:value-of select="@servingSize"/>
- </td>
- </tr>
- </table>
- <div class="viewLabel">
- <xsl:value-of select="key('i18n','recipe.ingredients.displayName')"/>: </div>
- <table class="view">
- <xsl:choose>
- <xsl:when test="../@mode = 'converted'">
- <xsl:apply-templates select="eat:ingredient" mode="converted"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="eat:ingredient" mode="display"/>
- </xsl:otherwise>
- </xsl:choose>
- </table>
- <xsl:if test="eat:step">
- <div class="viewLabel">
- <xsl:value-of select="key('i18n','recipe.steps.displayName')"/>: </div>
- <div class="viewBox">
- <ol>
- <xsl:apply-templates select="eat:step" mode="display"/>
- </ol>
- </div>
- </xsl:if>
- <br style="clear: both;"/>
- <xsl:if test="@createdDate">
- <div class="recipe-footer">
- <xsl:value-of select="key('i18n','created.on')"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="date:format-date(string(@createdDate),'d MMM yyyy')"/>
- <xsl:if test="eat:owner/@login">
- <xsl:text> </xsl:text>
- <xsl:value-of select="key('i18n','by')"/>
- <xsl:text> </xsl:text>
- <xsl:choose>
- <xsl:when test="$acting-user/../@admin = 'true'">
- <a href="{$web-context}/user.do?userId={eat:owner/@userId}"
- rel="popup|600|400|0|1">
- <xsl:value-of select="eat:owner/@login"/>
- </a>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="eat:owner/@login"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="$acting-user">
- <!-- handy link to search for all recipes creatd by a user -->
- <a title="{key('i18n','link.quick.searchowner.title')}"
- href="{$web-context}/search.do?mode=advanced&criteria.advanced[0].type=3&criteria.advanced[0].op=1&criteria.advanced[0].query={eat:owner/@login}">
- <img class="quicklink" width="8" height="9"
- src="{$web-context}/img/link-r.png"
- alt="{key('i18n','link.quick.searchowner')}"/>
- </a>
- </xsl:if>
- </xsl:if>
- </div>
- </xsl:if>
- </xsl:template>
- <xsl:template match="eat:recipe/eat:step" mode="display">
- <li>
- <xsl:value-of select="."/>
- </li>
- </xsl:template>
- <xsl:template match="eat:recipe/eat:ingredient" mode="converted">
- <xsl:variable name="system" select="../eat:system/@systemId"/>
- <xsl:variable name="mass" select="eat:unit/@mass"/>
- <tr>
- <xsl:choose>
- <xsl:when
- test="not(eat:unit) or ($system = 1 and eat:unit/@toUS = 0) or
- ($system = 2 and eat:unit/@toMetric = 0)">
- <!-- no conversion necessary -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:apply-templates select="eat:unit"/>
- </td>
- </xsl:when>
- <xsl:when test="$mass = 'true' and $system = 1">
- <!-- ok, dealing with US ounces: if over 16 oz convert to pounds -->
- <xsl:choose>
- <xsl:when test="@quantity < 16">
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity"/>
- <xsl:with-param name="abbreviation" select="'oz'"/>
- </xsl:call-template>
- </td>
- </xsl:when>
- <xsl:otherwise>
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity div 16.0"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity div 16.0"/>
- <xsl:with-param name="abbreviation" select="'lb'"/>
- </xsl:call-template>
- </td>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$mass = 'true' and $system = 2">
- <!-- ok, dealing with metric grams -->
- <xsl:choose>
- <xsl:when test="@quantity < 1">
- <!-- convert to milligrams -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity * 1000"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity * 1000"/>
- <xsl:with-param name="abbreviation" select="'mg'"/>
- </xsl:call-template>
- </td>
- </xsl:when>
- <xsl:when test="@quantity < 1000000">
- <!-- keep as grams -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity"/>
- <xsl:with-param name="abbreviation" select="'g'"/>
- </xsl:call-template>
- </td>
- </xsl:when>
- <xsl:otherwise>
- <!-- convert to kilograms -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity div 1000000.0"
- />
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity div 1000000.0"/>
- <xsl:with-param name="abbreviation" select="'kg'"/>
- </xsl:call-template>
- </td>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$mass = 'false' and $system = 1">
- <!-- ok, dealing with US teaspoons -->
- <xsl:choose>
- <xsl:when test="@quantity < 3">
- <!-- keep as teaspoons -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity"/>
- <xsl:with-param name="abbreviation" select="'t'"/>
- </xsl:call-template>
- </td>
- </xsl:when>
- <xsl:when test="@quantity < 12">
- <!-- convert to tablespoons -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity div 3.0"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity div 3.0"/>
- <xsl:with-param name="abbreviation" select="'T'"/>
- </xsl:call-template>
- </td>
- </xsl:when>
- <xsl:when test="@quantity < 768">
- <!-- convert to cups -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity div 48.0"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity div 48.0"/>
- <xsl:with-param name="abbreviation" select="'c'"/>
- </xsl:call-template>
- </td>
- </xsl:when>
- <xsl:otherwise>
- <!-- convert to gallons + fl oz -->
- <xsl:variable name="gallons" select="floor(@quantity div 768.0)"/>
- <xsl:variable name="ounces" select="@quantity mod 768"/>
- <xsl:comment> gals = <xsl:value-of select="$gallons"/> tsp =
- <xsl:value-of select="$ounces"/>
- </xsl:comment>
- <td colspan="2">
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="$gallons"/>
- </xsl:call-template>
- <xsl:text> </xsl:text>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="$gallons"/>
- <xsl:with-param name="abbreviation" select="'gal'"/>
- </xsl:call-template>
- <xsl:if test="$ounces > 0">
- <xsl:text>, </xsl:text>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="$ounces div 16.0"/>
- </xsl:call-template>
- <xsl:text> </xsl:text>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="$ounces div 16.0"/>
- <xsl:with-param name="abbreviation" select="'fl.oz'"/>
- </xsl:call-template>
- </xsl:if>
- </td>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$mass = 'false' and $system = 2">
- <!-- ok, dealing with metric milliliters -->
- <xsl:choose>
- <xsl:when test="@quantity < 1000">
- <!-- keep as milliliters -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity"/>
- <xsl:with-param name="abbreviation" select="'ml'"/>
- </xsl:call-template>
- </td>
- </xsl:when>
- <xsl:otherwise>
- <!-- convert to liters -->
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity div 1000.0"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:call-template name="ingredient-unit">
- <xsl:with-param name="quantity" select="@quantity div 1000.0"/>
- <xsl:with-param name="abbreviation" select="'L'"/>
- </xsl:call-template>
- </td>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:comment> ack! </xsl:comment>
- <!-- ack! -->
- </xsl:otherwise>
- </xsl:choose>
- <td>
- <xsl:text> </xsl:text>
- <xsl:apply-templates select="eat:ingredient"/>
- <xsl:apply-templates select="eat:recipe"/>
- <xsl:if test="string-length(@qualifier) > 0">
- <xsl:text> - </xsl:text>
- <i>
- <xsl:value-of select="@qualifier"/>
- </i>
- </xsl:if>
- </td>
- </tr>
- </xsl:template>
- <xsl:template match="eat:recipe/eat:ingredient" mode="display">
- <tr>
- <td>
- <xsl:call-template name="ingredient-quantity">
- <xsl:with-param name="quantity" select="@quantity"/>
- </xsl:call-template>
- </td>
- <td>
- <xsl:text> </xsl:text>
- <xsl:apply-templates select="eat:unit"/>
- <xsl:text> </xsl:text>
- <xsl:apply-templates select="eat:ingredient"/>
- <xsl:apply-templates select="eat:recipe"/>
- <xsl:if test="string-length(@qualifier) > 0">
- <xsl:text> - </xsl:text>
- <i>
- <xsl:value-of select="@qualifier"/>
- </i>
- </xsl:if>
- </td>
- </tr>
- </xsl:template>
- <xsl:template match="eat:base">
- <xsl:choose>
- <xsl:when test="$aux/eat:ui/eat:base">
- <xsl:variable name="base-id" select="@baseId"/>
- <xsl:value-of select="$aux/eat:ui/eat:base[@baseId = $base-id]"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="eat:course">
- <xsl:variable name="display-key">
- <xsl:text>course.</xsl:text>
- <xsl:choose>
- <xsl:when test="$aux/eat:ui/eat:course">
- <xsl:variable name="course-id" select="@courseId"/>
- <xsl:value-of
- select="translate($aux/eat:ui/eat:course[@courseId = $course-id],' ','')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="translate(string(.),' ','')"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="key('i18n',$display-key)">
- <xsl:value-of select="key('i18n',$display-key)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="eat:difficulty">
- <xsl:choose>
- <xsl:when test="$aux/eat:ui/eat:difficulty">
- <xsl:variable name="difficulty-id" select="@difficultyId"/>
- <xsl:value-of select="$aux/eat:ui/eat:difficulty[@difficultyId = $difficulty-id]"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="eat:ethnicity">
- <xsl:choose>
- <xsl:when test="$aux/eat:ui/eat:ethnicity">
- <xsl:variable name="ethnicity-id" select="@ethnicityId"/>
- <xsl:value-of select="$aux/eat:ui/eat:ethnicity[@ethnicityId = $ethnicity-id]"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="eat:prep-time">
- <xsl:choose>
- <xsl:when test="$aux/eat:ui/eat:prep-time">
- <xsl:variable name="preptime-id" select="@prepTimeId"/>
- <xsl:value-of select="$aux/eat:ui/eat:prep-time[@prepTimeId = $preptime-id]"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="eat:unit">
- <xsl:variable name="unit-key">
- <xsl:text>unit.</xsl:text>
- <xsl:choose>
- <xsl:when test="$aux/eat:ui/eat:unit">
- <xsl:variable name="unit-id" select="@unitId"/>
- <xsl:value-of
- select="translate($aux/eat:ui/eat:unit[@unitId = $unit-id]/@abbreviation,' ','')"
- />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="translate(@abbreviation,' ','')"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="../@quantity > 1">
- <xsl:text>.plural</xsl:text>
- </xsl:if>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="key('i18n',$unit-key)">
- <xsl:value-of select="key('i18n',$unit-key)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
-
- </xsl:template>
- <xsl:template match="eat:ingredient">
- <xsl:choose>
- <xsl:when test="$aux/eat:ui/eat:ingredient">
- <xsl:variable name="ingredient-id" select="@ingredientId"/>
- <xsl:value-of
- select="$aux/eat:ui/eat:ingredient[@ingredientId = $ingredient-id]/eat:name"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="eat:name"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="eat:ingredient/eat:recipe">
- <a href="{$web-context}/recipe.do?recipeId={@recipeId}">
- <xsl:choose>
- <xsl:when test="string-length(eat:name) = 0">
- <xsl:variable name="recipe-id" select="@recipeId"/>
- <xsl:value-of select="$aux/eat:ui/eat:recipe[@recipeId = $recipe-id]/eat:name"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="eat:name"/>
- </xsl:otherwise>
- </xsl:choose>
- </a>
- </xsl:template>
- <xsl:template name="ingredient-quantity">
- <xsl:param name="quantity"/>
- <xsl:variable name="whole">
- <xsl:choose>
- <xsl:when test="contains($quantity,'.')">
- <xsl:value-of select="substring-before($quantity,'.')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$quantity"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="frac" select="$quantity - $whole"/>
- <!--
- <xsl:comment>
- whole = <xsl:value-of select="$whole"/>
- frac = <xsl:value-of select="$frac"/>
- </xsl:comment>
- -->
- <xsl:choose>
- <xsl:when test="$frac = 0">
- <xsl:value-of select="$whole"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:if test="not($whole = 0)">
- <xsl:value-of select="$whole"/>
- <xsl:text> </xsl:text>
- </xsl:if>
- <xsl:choose>
- <xsl:when test="$frac = .75">
- <xsl:text>¾</xsl:text>
- </xsl:when>
- <xsl:when
- test="(format-number($frac,'.00') = '.67') or (format-number($frac,'.00') = '.66')">
- <xsl:text>⅔</xsl:text>
- </xsl:when>
- <xsl:when test="$frac = .5">
- <xsl:text>½</xsl:text>
- </xsl:when>
- <xsl:when test="format-number($frac,'.00') = '.33'">
- <xsl:text>⅓</xsl:text>
- </xsl:when>
- <xsl:when test="$frac = .25">
- <xsl:text>¼</xsl:text>
- </xsl:when>
- <xsl:when test="floor($frac * 8) = $frac * 8">
- <xsl:value-of select="$frac * 8"/>
- <xsl:text>/8</xsl:text>
- </xsl:when>
- <xsl:when test="floor($frac * 16) = $frac * 16">
- <xsl:value-of select="$frac * 16"/>
- <xsl:text>/16</xsl:text>
- </xsl:when>
- <xsl:when test="floor($frac * 32) = $frac * 32">
- <xsl:value-of select="$frac * 32"/>
- <xsl:text>/32</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="format-number($frac,'.00#')"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="ingredient-unit">
- <xsl:param name="quantity"/>
- <xsl:param name="abbreviation"/>
- <xsl:variable name="unit-key">
- <xsl:text>unit.</xsl:text>
- <xsl:choose>
- <xsl:when test="$abbreviation">
- <xsl:value-of select="translate($abbreviation,' ','')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="unit-id" select="@unitId"/>
- <xsl:value-of
- select="translate($aux/eat:ui/eat:unit[@unitId = $unit-id]/@abbreviation,' ','')"
- />
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="$quantity > 1">
- <xsl:text>.plural</xsl:text>
- </xsl:if>
- </xsl:variable>
- <xsl:value-of select="key('i18n',$unit-key)"/>
- </xsl:template>
- </xsl:stylesheet>
|