| | </xsl:template> |
| | |
| | +<!-- Pre-heated oven temperature, not to be confused with ingredient prep. --> |
| | <xsl:template match="preparation"> |
| | <xsl:apply-templates /> |
 |
| | <xsl:apply-templates select="ingredient" /> |
| | <xsl:text>\end{ingredients}

</xsl:text> |
| | + |
| | <!-- |
| | - | If any ingredients contain non-empty condition, |
| | - | do a preparation section. |
| | + | If non-empty conditions exist, insert a preparation section. |
| | +--> |
| | <xsl:if test="ingredient[@condition != '']"> |
| | - <xsl:call-template name="prepare-ingredients"> |
| | - <xsl:with-param name="ingredList" select="." /> |
| | - </xsl:call-template> |
| | + <xsl:text>\begin{preparation}
</xsl:text> |
| | + <xsl:apply-templates select="ingredient[@condition != '']" mode="prep" /> |
| | + <xsl:text>\end{preparation}
</xsl:text> |
| | </xsl:if> |
| | </xsl:template> |
 |
| | <xsl:value-of select="@unit" /> |
| | <xsl:text>}{</xsl:text> |
| | - <xsl:if test="@condition !=''"> |
| | - <xsl:apply-templates select="@condition" /> |
| | - <xsl:text> </xsl:text> |
| | - </xsl:if> |
| | <xsl:apply-templates select="key('preg', @id)/@name" /> |
| | <xsl:text>}
</xsl:text> |
| | + |
| | + <!-- Put the ingredients in a categorized list. --> |
| | <xsl:if test="key('preg',@id)/categories/category"> |
| | <xsl:for-each select="key('preg',@id)/categories/category"> |
 |
| | </xsl:for-each> |
| | </xsl:if> |
| | + |
| | + <!-- Put the ingredients in a flat list. --> |
| | <xsl:text>\index[flatingred]{</xsl:text> |
| | <xsl:apply-templates select="key('preg', @id)/@name" /> |
| | <xsl:text>}
</xsl:text> |
| | +</xsl:template> |
| | + |
| | +<!-- |
| | + | Extracts preparation instructions from ingredients. |
| | + +--> |
| | +<xsl:template match="ingredient[@condition != '']" mode="prep"> |
| | + <xsl:for-each select="."> |
| | + <xsl:text>\item </xsl:text> |
| | + <xsl:apply-templates select="@condition" mode="prep" /> |
| | + <xsl:text> the </xsl:text> |
| | + <xsl:apply-templates select="key('preg', @id)/@name" /> |
| | + <xsl:text>.
</xsl:text> |
| | + </xsl:for-each> |
| | +</xsl:template> |
| | + |
| | +<!-- |
| | + | Splits the ingredient preconditions using the Oxford serial comma: |
| | + | http://www.mhonarc.org/archive/html/xsl-list/2008-06/msg00401.html |
| | + | by Ronnie Royston |
| | + +--> |
| | +<xsl:template match="@condition" mode="prep"> |
| | + <xsl:variable name="actions" select="str:tokenize( ., ',' )" /> |
| | + <xsl:variable name="tokens" select="count( $actions )" /> |
| | + |
| | + <xsl:variable name="condition"> |
| | + <xsl:for-each select="$actions"> |
| | + <xsl:choose> |
| | + <xsl:when test="$tokens > 2"> |
| | + <xsl:choose> |
| | + <xsl:when test="position()=1"> |
| | + <xsl:value-of select="concat(' ', ., ',')"/> |
| | + </xsl:when> |
| | + <xsl:when test="position()=last()"> |
| | + <xsl:value-of select="concat(' and ', .)"/> |
| | + </xsl:when> |
| | + <xsl:otherwise> |
| | + <xsl:value-of select="concat(' ', .,',')"/> |
| | + </xsl:otherwise> |
| | + </xsl:choose> |
| | + </xsl:when> |
| | + <xsl:when test="$tokens = 2"> |
| | + <xsl:choose> |
| | + <xsl:when test="position()=1"> |
| | + <xsl:value-of select="concat(' ', .,' and')"/> |
| | + </xsl:when> |
| | + <xsl:otherwise> |
| | + <xsl:value-of select="concat(' ', .)"/> |
| | + </xsl:otherwise> |
| | + </xsl:choose> |
| | + </xsl:when> |
| | + <xsl:otherwise> |
| | + <xsl:value-of select="concat(' ', .)"/> |
| | + </xsl:otherwise> |
| | + </xsl:choose> |
| | + </xsl:for-each> |
| | + </xsl:variable> |
| | + |
| | + <xsl:call-template name="escape"> |
| | + <xsl:with-param |
| | + name="e" select="string:capitalize(normalize-space($condition))" /> |
| | + </xsl:call-template> |
| | </xsl:template> |
| | |
 |
| | </xsl:call-template> |
| | </xsl:if> |
| | -</xsl:template> |
| | - |
| | -<!-- |
| | - | Extracts preparation instructions from ingredients |
| | - +--> |
| | -<xsl:template name="prepare-ingredients"> |
| | - <xsl:param name="ingredList" /> |
| | - <xsl:text>\begin{preparation}
</xsl:text> |
| | - <xsl:for-each select="$ingredList/ingredient[@condition != '']"> |
| | - <xsl:text>\item </xsl:text> |
| | - <xsl:call-template name="escape-capitalize"> |
| | - <xsl:with-param name="ec" select="@condition" /> |
| | - </xsl:call-template> |
| | -<!-- <xsl:call-template name="Oxford-comma"> |
| | - <xsl:with-param name="pText" select="@condition" /> |
| | - </xsl:call-template> |
| | ---> |
| | - <xsl:text> the </xsl:text> |
| | - <xsl:apply-templates select="key('preg', @id)/@name" /> |
| | - <xsl:text>.
</xsl:text> |
| | - </xsl:for-each> |
| | - <xsl:text>\end{preparation}
</xsl:text> |
| | -</xsl:template> |
| | - |
| | -<!-- |
| | - | Oxford serial comma. Taken from |
| | - | http://www.mhonarc.org/archive/html/xsl-list/2008-06/msg00401.html |
| | - | by Ronnie Royston |
| | - +--> |
| | -<xsl:template name="Oxford-comma"> |
| | - <xsl:param name="pText" /> |
| | - <xsl:variable name="pList" select="string:split($pText)" /> |
| | - <xsl:for-each select="$pList/nodeset"> |
| | - <xsl:choose> |
| | - <xsl:when test="count(node) > 2"> |
| | - <xsl:choose> |
| | - <xsl:when test="position()=1"> |
| | - <xsl:value-of select="concat(' ', .,',')"/> |
| | - </xsl:when> |
| | - <xsl:when test="position()=last()"> |
| | - <xsl:value-of select="concat(' and ', .,'. ')"/> |
| | - </xsl:when> |
| | - <xsl:otherwise> |
| | - <xsl:value-of select="concat(' ', .,',')"/> |
| | - </xsl:otherwise> |
| | - </xsl:choose> |
| | - </xsl:when> |
| | - <xsl:when test="count(node) = 2"> |
| | - <xsl:choose> |
| | - <xsl:when test="position()=1"> |
| | - <xsl:value-of select="concat(' ', .,' and')"/> |
| | - </xsl:when> |
| | - <xsl:otherwise> |
| | - <xsl:value-of select="concat(' ', .,'. ')"/> |
| | - </xsl:otherwise> |
| | - </xsl:choose> |
| | - </xsl:when> |
| | - <xsl:otherwise> |
| | - <xsl:value-of select="concat(' ', .,'. ')"/> |
| | - </xsl:otherwise> |
| | - </xsl:choose> |
| | - </xsl:for-each> |
| | </xsl:template> |
| | |