<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	xmlns:eat="http://msqr.us/xsd/ieat"
	xmlns:xweb="http://msqr.us/xsd/jaxb-web"
	exclude-result-prefixes="eat xweb">
	
	<xsl:import href="global-variables.xsl"/>

	<xsl:template match="eat:meal" mode="display">
		<h2>
			<xsl:value-of select="eat:name"/>
		</h2>
		<xsl:apply-templates select="." mode="display-internal"/>
	</xsl:template>
	
	<xsl:template match="eat:meal" mode="display-internal">
		<ol>
			<!-- Note: the [eat:recipe] clause is to hide "orphaned" meal
			     recipes that occur after deleting a recipe that belongs 
			     in a meal 
			-->
			<xsl:apply-templates select="eat:recipe[eat:recipe]" mode="meal-display"/>
		</ol>
	</xsl:template>
	
	<xsl:template match="eat:meal/eat:recipe" mode="meal-display">
		<li>
			<b>
				<xsl:choose>
					<xsl:when test="string-length(eat:recipe/eat:name) &gt; 0">
						<xsl:value-of select="eat:recipe/eat:name"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:variable name="recipe-id" select="eat:recipe/@recipeId"></xsl:variable>
						<xsl:value-of select="$aux/eat:ui/eat:recipe[@recipeId = $recipe-id]/eat:name"/>
					</xsl:otherwise>
				</xsl:choose>
			</b>
			<br/>
			<span class="caption">
				<xsl:apply-templates select="eat:course"/>
				<xsl:text>, </xsl:text>
				<xsl:value-of select="key('i18n','mealRecipe.quantity.displayName')"/>
				<xsl:text>: </xsl:text>
				<xsl:value-of select="@quantity"/>
			</span>
			<p>
				<xsl:choose>
					<xsl:when test="string-length(eat:recipe/eat:excerpt) &gt; 0">
						<xsl:value-of select="eat:recipe/eat:excerpt"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:variable name="recipe-id" select="eat:recipe/@recipeId"></xsl:variable>
						<xsl:value-of select="$aux/eat:ui/eat:recipe[@recipeId = $recipe-id]/eat:excerpt"/>
					</xsl:otherwise>
				</xsl:choose>
			</p>
		</li>
	</xsl:template>
	
</xsl:stylesheet>