Dave Jarvis' Repositories

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

XSL now handles the new ingredients model in XML. XSL now looks up inredient names from a centralised list in the XML. Ingredients are indexed twice, 1) in a "flat" alphabetical list of all ingredients; 2) in a categorised list (when the categories are given). Actual heading/formatting of the subindices will be addressed in issue (Note that the XSL code can probably be optimised further.)

Author liantze <email>
Date 2013-02-18 00:46:15 GMT+0800
Commit 659f29a30fdf916c83c9eb1569a4ff9eb90314b2
Parent 55aa50a
Delta 22 lines added, 7 lines removed, 15-line increase
xsl/latex.xsl
-->
+<xsl:key name="preg" match="/recipe-book/ingredients/ingredient" use="@id" />
+
<xsl:template match="/recipe-book">
<xsl:text>\documentclass{recipe-book}&#xa;</xsl:text>
<xsl:text>\usepackage{hyperref}&#xa;</xsl:text>
<xsl:value-of select="$preamble" />
- <xsl:text>\makeindex&#xa;</xsl:text>
+ <xsl:text>\makeindex[flatingred]&#xa;</xsl:text>
+ <xsl:text>\makeindex[catingred]&#xa;</xsl:text>
<xsl:apply-templates select='book' />
<xsl:text>\begin{document}&#xa;</xsl:text>
<xsl:apply-templates select="*[name()!='book']" />
<xsl:if test="$ingredient-index">
- <xsl:text>\printindex&#xa;</xsl:text>
+ <xsl:text>\printindex[flatingred]&#xa;</xsl:text>
+ <xsl:text>\printindex[catingred]&#xa;</xsl:text>
</xsl:if>
<xsl:text>\end{document}&#xa;</xsl:text>
</xsl:template>
-<xsl:template match="ingredients[descendant::text()]">
+<xsl:template match="ingredients[parent::recipe]">
<xsl:text>\begin{ingredients}&#xa;</xsl:text>
<xsl:apply-templates select="@label" />
<xsl:text>}{</xsl:text>
<xsl:if test="@condition !=''">
- <xsl:value-of select="@condition" />
+ <xsl:apply-templates select="@condition" />
<xsl:text> </xsl:text>
</xsl:if>
- <xsl:value-of select="." />
- <xsl:text>}\index{</xsl:text>
- <xsl:apply-templates />
+ <xsl:apply-templates select="key('preg', @id)/@name" />
<xsl:text>}&#xa;</xsl:text>
+ <xsl:if test="key('preg',@id)/categories/category">
+ <xsl:for-each select="key('preg',@id)/categories/category">
+ <xsl:text>\index[catingred]{</xsl:text>
+ <xsl:apply-templates select="@name" />
+ <xsl:text>!</xsl:text>
+ <xsl:apply-templates select="../../@name" />
+ <xsl:text>}&#xa;</xsl:text>
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:text>\index[flatingred]{</xsl:text>
+ <xsl:apply-templates select="key('preg', @id)/@name" />
+ <xsl:text>}&#xa;</xsl:text>
</xsl:template>
+
<xsl:template match="directions[1]">