| | |
| | <xsl:import href="string-utilities.xsl" /> |
| | - |
| | <xsl:output method="text" encoding="utf-8" /> |
| | <xsl:strip-space elements="*" /> |
 |
| | <xsl:param name="book-back-cover" select="" /> |
| | --> |
| | - |
| | -<!-- |
| | - | Provides output escaping around user-defined text. This ensures that |
| | - | users cannot embed malicious LaTeX code inside their recipes. |
| | - | |
| | - | All text that needs to be escaped ultimately is transformed through this |
| | - | template. |
| | - | |
| | - | @param e - The string to escape. |
| | - | @see http://stackoverflow.com/a/2627303/59087 |
| | - | @see http://tex.stackexchange.com/q/97448/2148 |
| | - +--> |
| | -<xsl:template name="escape"> |
| | - <xsl:param name="e" /> |
| | - |
| | - <xsl:value-of select="$e" /> |
| | -</xsl:template> |
| | - |
| | -<!-- |
| | - | Normalizes and capitalizes all the words of an escaped string. |
| | - | |
| | - | @param ec - The string to normalize, capitalize, and escape. |
| | - +--> |
| | -<xsl:template name="escape-capitalize"> |
| | - <xsl:param name="ec" /> |
| | - |
| | - <xsl:variable name="escaped"> |
| | - <xsl:call-template name="escape"> |
| | - <xsl:with-param name="e" select="$ec" /> |
| | - </xsl:call-template> |
| | - </xsl:variable> |
| | - |
| | - <xsl:value-of select="normalize-space(string:capitalize-words($escaped))" /> |
| | -</xsl:template> |
| | - |
| | -<xsl:template match="text()" mode="escape"> |
| | - <xsl:call-template name="escape"> |
| | - <xsl:with-param name="e" select="." /> |
| | - </xsl:call-template> |
| | -</xsl:template> |
| | - |
| | -<xsl:template match="text()" mode="escape-capitalize"> |
| | - <xsl:call-template name="escape-capitalize"> |
| | - <xsl:with-param name="ec" select="." /> |
| | - </xsl:call-template> |
| | -</xsl:template> |
| | - |
| | -<xsl:template match="/" > |
| | - <xsl:apply-templates /> |
| | -</xsl:template> |
| | |
| | -<xsl:template match="recipe-book"> |
| | +<xsl:template match="/recipe-book"> |
| | <xsl:text>\documentclass{recipe-book}
</xsl:text> |
| | <xsl:text>\usepackage{hyperref}
</xsl:text> |
 |
| | </xsl:template> |
| | |
| | +<!-- |
| | + | Meta information about the book. |
| | + +--> |
| | <xsl:template match="book"> |
| | <xsl:text>\title{</xsl:text> |
 |
| | <xsl:apply-templates select="author" mode="escape-capitalize" /> |
| | <xsl:text>}
</xsl:text> |
| | - <xsl:apply-templates select="photo[@use='front-cover']/uri" /> |
| | -</xsl:template> |
| | - |
| | -<xsl:template match="photo[@use='front-cover']/uri"> |
| | - <xsl:if test="$book-front-cover"> |
| | - <xsl:text>\frontcoverphoto{</xsl:text> |
| | - <xsl:apply-templates /> |
| | - <xsl:text>}
</xsl:text> |
| | - </xsl:if> |
| | + <xsl:apply-templates select="photo" mode="book" /> |
| | </xsl:template> |
| | |
| | +<!-- |
| | + | Transforms the recipe from XML into LaTeX. |
| | + +--> |
| | <xsl:template match="recipe"> |
| | <xsl:text>\begin{recipe}{</xsl:text> |
| | <xsl:apply-templates select="description/title" /> |
| | <xsl:text>}
</xsl:text> |
| | - <xsl:apply-templates select="description/photo/uri" /> |
| | + <xsl:apply-templates select="description/photo" mode="recipe" /> |
| | <xsl:apply-templates /> |
| | <xsl:text>\end{recipe}

</xsl:text> |
| | </xsl:template> |
| | |
| | -<xsl:template match="description/title"> |
| | - <xsl:apply-templates mode="escape-capitalize" /> |
| | +<xsl:template match="photo[@use='front-cover']" mode="book"> |
| | + <xsl:apply-templates select="uri" mode="book" /> |
| | </xsl:template> |
| | |
| | -<xsl:template match="photo[@use='recipe-inset']/uri"> |
| | +<xsl:template match="photo[@use='recipe-inset']" mode="recipe"> |
| | + <xsl:apply-templates select="uri" mode="recipe-inset" /> |
| | +</xsl:template> |
| | + |
| | +<xsl:template match="uri" mode="book"> |
| | + <xsl:if test="$book-front-cover"> |
| | + <xsl:text>\frontcoverphoto{</xsl:text> |
| | + <xsl:apply-templates /> |
| | + <xsl:text>}
</xsl:text> |
| | + </xsl:if> |
| | +</xsl:template> |
| | + |
| | +<xsl:template match="uri" mode="recipe-inset"> |
| | <xsl:text>\insetphoto{</xsl:text> |
| | <xsl:apply-templates /> |
| | <xsl:text>}
</xsl:text> |
| | </xsl:template> |
| | |
| | +<xsl:template match="description/title"> |
| | + <xsl:apply-templates mode="escape-capitalize" /> |
| | +</xsl:template> |
| | |
| | <xsl:template match="preparation"> |
 |
| | <xsl:template match="equipment[descendant::text()]"> |
| | <xsl:text>\begin{equipment}
</xsl:text> |
| | - <!-- select non-empty child nodes --> |
| | + <!-- Select non-empty child nodes. --> |
| | <xsl:for-each select="*[child::*]"> |
| | <xsl:text> \item[</xsl:text> |
 |
| | <xsl:apply-templates mode="escape" /> |
| | <xsl:text>.
</xsl:text> |
| | +</xsl:template> |
| | + |
| | +<!-- |
| | + | Provides output escaping around user-defined text. This ensures that |
| | + | users cannot embed malicious LaTeX code inside their recipes. |
| | + | |
| | + | All text that needs to be escaped ultimately is transformed through this |
| | + | template. |
| | + | |
| | + | @param e - The string to escape. |
| | + | @see http://stackoverflow.com/a/2627303/59087 |
| | + | @see http://tex.stackexchange.com/q/97448/2148 |
| | + +--> |
| | +<xsl:template name="escape"> |
| | + <xsl:param name="e" /> |
| | + |
| | + <xsl:value-of select="$e" /> |
| | +</xsl:template> |
| | + |
| | +<!-- |
| | + | Normalizes and capitalizes all the words of an escaped string. |
| | + | |
| | + | @param ec - The string to normalize, capitalize, and escape. |
| | + +--> |
| | +<xsl:template name="escape-capitalize"> |
| | + <xsl:param name="ec" /> |
| | + |
| | + <xsl:variable name="escaped"> |
| | + <xsl:call-template name="escape"> |
| | + <xsl:with-param name="e" select="$ec" /> |
| | + </xsl:call-template> |
| | + </xsl:variable> |
| | + |
| | + <xsl:value-of select="normalize-space(string:capitalize-words($escaped))" /> |
| | +</xsl:template> |
| | + |
| | +<xsl:template match="text()" mode="escape"> |
| | + <xsl:call-template name="escape"> |
| | + <xsl:with-param name="e" select="." /> |
| | + </xsl:call-template> |
| | +</xsl:template> |
| | + |
| | +<xsl:template match="text()" mode="escape-capitalize"> |
| | + <xsl:call-template name="escape-capitalize"> |
| | + <xsl:with-param name="ec" select="." /> |
| | + </xsl:call-template> |
| | </xsl:template> |
| | |