| | <xsl:apply-templates select="ingredient" /> |
| | <xsl:text>\end{ingredients}

</xsl:text> |
| | + <!-- |
| | + | If any ingredients contain non-empty condition, |
| | + | do a preparation section. |
| | + +--> |
| | + <xsl:if test="ingredient[@condition != '']"> |
| | + <xsl:call-template name="prepare-ingredients"> |
| | + <xsl:with-param name="ingredList" select="." /> |
| | + </xsl:call-template> |
| | + </xsl:if> |
| | </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> |
| | |