Dave Jarvis' Repositories

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

Transforms the XML to extract preparation instructions.

Author liantze <email>
Date 2013-02-23 00:50:15 GMT+0800
Commit b7b0a4539b47c62edc80191f5efc4e7564404c9f
Parent 92c5e3f
xsl/latex.xsl
<xsl:apply-templates select="ingredient" />
<xsl:text>\end{ingredients}&#xa;&#xa;</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}&#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, 0 lines removed, 71-line increase