Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/recipe-books.git

Serial comma. ;-)

Author Dave Jarvis <email>
Date 2013-02-22 22:05:26 GMT-0800
Commit c9d144ba219aad4a22ba431c7fc1091b1fbb4993
Parent b7b0a45
xsl/latex.xsl
</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}&#xa;&#xa;</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}&#xa;</xsl:text>
+ <xsl:apply-templates select="ingredient[@condition != '']" mode="prep" />
+ <xsl:text>\end{preparation}&#xa;</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>}&#xa;</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>}&#xa;</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>.&#xa;</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}&#xa;</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>.&#xa;</xsl:text>
- </xsl:for-each>
- <xsl:text>\end{preparation}&#xa;</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>
Delta 71 lines added, 71 lines removed