<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:param name="get_name">25</xsl:param>

<!-- MAIN TEMPLATE -->
<xsl:template match="/beer_recipes">
    <xsl:for-each select="recipe">
        <xsl:if test="name/@number=$get_name">

            <!-- root element contains the whole document -->
            <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

                <!-- page layouts (we only have one, called "main" -->
                <fo:layout-master-set>
                    <fo:simple-page-master
                        master-name="main"
                        margin-top="0.5in"   margin-bottom="0.5in"
                        margin-left="0.5in"  margin-right="0.5in"
                        page-width="8.5in"   page-height="11.0in">
                        <fo:region-before extent="0.5in"/>
                        <fo:region-after extent="0.5in"/>
                        <fo:region-start extent="0.5in"/>
                        <fo:region-end extent="0.5in"/>
                        <fo:region-body
                            margin-top="0.5in"   margin-bottom="0.5in"
                            margin-left="0.5in"  margin-right="0.5in"/>
                    </fo:simple-page-master>
                </fo:layout-master-set>

                <!-- page styles (all the same here) -->
                <fo:page-sequence master-reference="main">

                    <!-- Flow element? -->
                    <fo:flow flow-name="xsl-region-body">

                        <!-- Title -->
                        <fo:block
                            font-family="title" font-size="14pt"
                            text-align="center">
                            <xsl:text>#</xsl:text>
                            <xsl:value-of select="name/@number"/>
                            <xsl:text>: </xsl:text>
                            <xsl:value-of select="name"/>
                            <xsl:text> (</xsl:text>
                            <xsl:value-of select="style"/>
                            <xsl:text>)</xsl:text>
                        </fo:block>

                        <!-- Brewer -->
                        <fo:block
                            font-family="author" font-size="10pt" 
                            text-align="center"
                            space-before="0pt" space-after="2pt">
                            <xsl:for-each select="brewer">
                                <xsl:value-of select="."/>
                                <xsl:text> </xsl:text>
                            </xsl:for-each>
                            <xsl:text> (</xsl:text>
                            <xsl:value-of select="date"/>
                            <xsl:text>)</xsl:text>
                        </fo:block>

                        <!-- Description -->
                        <xsl:apply-templates select="descrip"/>
                        
                        <!-- Recipe -->
                        <fo:block
                            font-family="rm" font-size="9pt"
                            space-before="3pt" space-after="1pt">
                            <fo:wrapper font-family="bold" font-size="9pt">Recipe</fo:wrapper>
                            <xsl:text> (for </xsl:text>
                            <xsl:value-of select="number(boil/end/volume) - 0.5"/>
                            <!-- <xsl:text>&#160;</xsl:text> -->
                            <xsl:text> </xsl:text>
                            <xsl:value-of select="boil/end/volume/@type"/>
                            <xsl:text> final volume)</xsl:text>
                        </fo:block>
                        <fo:table
                            font-family="rm" font-size="9pt"
                            table-layout="fixed">
                            <fo:table-column column-width="0.50in"/>
                            <fo:table-column column-width="0.65in"/>
                            <fo:table-column column-width="0.50in"/>
                            <fo:table-column column-width="4.85in"/>
                            <fo:table-body>
                                <xsl:apply-templates select="ingredients"/>
                            </fo:table-body>
                        </fo:table>

                        <!-- Water -->
                        <fo:block
                            font-family="bold" font-size="9pt"
                            space-before="2pt" space-after="1pt">
                            <xsl:text>Water</xsl:text>
                        </fo:block>
                        <fo:list-block
                            font-family="rm" font-size="9pt">
                            <xsl:apply-templates select="ingredients/water"/>
                        </fo:list-block>

                        <!-- Mash -->
                        <fo:block
                            font-family="bold" font-size="9pt"
                            space-before="2pt" space-after="1pt">
                            <xsl:text>Mash</xsl:text>
                        </fo:block>
                        <fo:block
                            font-family="rm" font-size="9pt">
                            <xsl:apply-templates select="ingredients/adjuncts/adjunct/comment"/>
                        </fo:block>
                        <fo:list-block
                            font-family="rm" font-size="9pt">
                            <xsl:apply-templates select="mash"/>
                        </fo:list-block>
                        
                        <!-- Sparge -->
                        <fo:block
                            font-family="bold" font-size="9pt"
                            space-before="2pt" space-after="1pt">
                            <xsl:text>Sparge</xsl:text>
                        </fo:block>
                        <fo:list-block
                            font-family="rm" font-size="9pt">
                            <xsl:apply-templates select="sparge"/>
                        </fo:list-block>
                        
                        <!-- Boil -->
                        <fo:block
                            font-family="bold" font-size="9pt"
                            space-before="2pt" space-after="1pt">
                            <xsl:text>Boil</xsl:text>
                        </fo:block>
                        <fo:list-block
                            font-family="rm" font-size="9pt">
                            <xsl:apply-templates select="boil"/>
                        </fo:list-block>
                        
                        <!-- Fermentation -->
                        <fo:block
                            font-family="bold" font-size="9pt"
                            space-before="2pt" space-after="1pt">
                            <xsl:text>Fermentation</xsl:text>
                        </fo:block>
                        <fo:list-block
                            font-family="rm" font-size="9pt">
                            <xsl:apply-templates select="fermentation"/>
                        </fo:list-block>
                        
                        <!-- Packaging -->
                        <fo:block
                            font-family="bold" font-size="9pt"
                            space-before="2pt" space-after="1pt">
                            <xsl:text>Packaging</xsl:text>
                        </fo:block>
                        <fo:list-block
                            font-family="rm" font-size="9pt">
                            <xsl:apply-templates select="packaging"/>
                        </fo:list-block>
                        
                        <!-- Properties -->
                        <fo:block
                            font-family="bold" font-size="9pt"
                            space-before="2pt" space-after="1pt">
                            <xsl:text>Properties</xsl:text>
                        </fo:block>
                        <fo:table
                            font-family="rm" font-size="9pt"
                            table-layout="fixed">
                            <fo:table-column column-width="1.6in"/>
                            <fo:table-column column-width="1.2in"/>
                            <fo:table-column column-width="1.4in"/>
                            <fo:table-column column-width="1.2in"/>
                            <fo:table-body>
                                <xsl:apply-templates select="predicted_data"/>
                            </fo:table-body>
                        </fo:table>

                        <!-- Tasting Notes, Brewing Notes, Comments -->
                        <xsl:apply-templates select="brewing_notes"/>
                        <xsl:apply-templates select="tasting_notes"/>
                        <xsl:apply-templates select="comment" mode="list-block"/>

                    </fo:flow>
                </fo:page-sequence>
            </fo:root>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

<!-- DESCRIPTION -->
<xsl:template match="descrip">
  <fo:block
    font-family="rm"  font-size="9pt"
    start-indent="0.5in" end-indent="0.5in">
    <xsl:value-of select="."/>
  </fo:block>
</xsl:template>

<!-- INGREDIENTS -->
<xsl:template match="ingredients">
    <xsl:apply-templates select="grains"/>
    <xsl:apply-templates select="adjuncts"/>
    <xsl:apply-templates select="hops"/>
    <xsl:apply-templates select="spices"/>
    <xsl:apply-templates select="others"/>
    <xsl:apply-templates select="yeast"/>
</xsl:template>

<xsl:template match="grains">
    <xsl:for-each select="grain">
        <fo:table-row>
            <xsl:apply-templates select="weight" mode="with-percentage"/>
            <fo:table-cell>
                <fo:block>
                    <xsl:value-of select="gname"/>
                    <xsl:apply-templates select="comment" mode="paren"/>
                </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:for-each>
</xsl:template>
           
<xsl:template match="adjuncts">
    <xsl:for-each select="adjunct">
        <fo:table-row>
            <xsl:apply-templates select="weight" mode="with-percentage"/>
            <fo:table-cell>
                <fo:block>
                    <xsl:value-of select="aname"/>
                    <xsl:apply-templates select="comment" mode="adjunct_ref"/>
                </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:for-each>
</xsl:template>

<xsl:template match="hops">
    <fo:table-row>
        <fo:table-cell><fo:block line-height="2pt">&#160;</fo:block></fo:table-cell>
    </fo:table-row>
    <xsl:for-each select="hop">
        <fo:table-row>
            <xsl:apply-templates select="weight"/>
            <fo:table-cell>
                <fo:block>
                    <xsl:value-of select="hname"/>
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="@type"/>
                    <xsl:text> hops, </xsl:text>
                    <xsl:value-of select="hname/@aa"/>
                    <xsl:text>% AA </xsl:text>
                    <xsl:apply-templates select="time" mode="paren"/>
                    <xsl:apply-templates select="first_wort"/>
                    <xsl:apply-templates select="secondary_hop"/>
                    <xsl:apply-templates select="keg_hop"/>
                </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:for-each>
</xsl:template>

<xsl:template match="first_wort">
    <xsl:text>(first wort hop)</xsl:text>
</xsl:template>

<xsl:template match="secondary_hop">
    <xsl:text>(dry hopped in secondary)</xsl:text>
</xsl:template>

<xsl:template match="keg_hop">
    <xsl:text>(dry hopped in keg)</xsl:text>
</xsl:template>

<!-- SPICES -->
<xsl:template match="spices">
    <fo:table-row>
        <fo:table-cell><fo:block line-height="2pt">&#160;</fo:block></fo:table-cell>
    </fo:table-row>
    <xsl:for-each select="spice">
        <fo:table-row>
            <xsl:apply-templates select="weight"/>
            <xsl:apply-templates select="volume"/>
            <fo:table-cell>
                <fo:block>
                    <xsl:value-of select="sname"/>
                    <xsl:text> </xsl:text>
                    <xsl:apply-templates select="time" mode="paren"/>
                    <xsl:apply-templates select="liquor_infusion"/>
                    <xsl:apply-templates select="secondary_spiced"/>
                    <xsl:apply-templates select="keg_spiced"/>
                </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:for-each>
</xsl:template>

<xsl:template match="liquor_infusion">
  <xsl:text>(Soaked in </xsl:text>
  <xsl:value-of select="."/>
  <xsl:text>, added at conditioning)</xsl:text>
</xsl:template>

<xsl:template match="secondary_spiced">
    <xsl:text>(added to secondary)</xsl:text>
</xsl:template>

<xsl:template match="keg_spiced">
    <xsl:text>(added to keg)</xsl:text>
</xsl:template>

<!-- WATER -->
<xsl:template match="water">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:value-of select="wname"/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
    <xsl:apply-templates select="treatments"/>
</xsl:template>

<xsl:template match="treatments">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:apply-templates select="volume" mode="notable"/>
                <!-- <xsl:text>&#160;</xsl:text> -->
                <xsl:text> </xsl:text>
                <xsl:value-of select="@type"/>
                <xsl:text> water treated with:</xsl:text>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
    <fo:list-item>
        <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label>
        <!-- <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label> -->
        <fo:list-item-body start-indent="0.3in">
            <fo:list-block>
                <xsl:for-each select="treatment">
                    <fo:list-item>
                        <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label>
                        <!-- <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label> -->
                        <fo:list-item-body start-indent="0.3in">
                            <fo:block>
                                <xsl:apply-templates select="weight" mode="notable"/>
                                <xsl:apply-templates select="volume" mode="notable"/>
                                <!-- <xsl:text>&#160;</xsl:text> -->
                                <xsl:text> </xsl:text>
                                <xsl:value-of select="tname"/>
                                <xsl:apply-templates select="comment"/>
                            </fo:block>
                        </fo:list-item-body>
                    </fo:list-item>
                </xsl:for-each>
            </fo:list-block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<!-- YEAST -->
<xsl:template match="yeast">
    <fo:table-row>
        <fo:table-cell><fo:block line-height="2pt">&#160;</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
        <fo:table-cell number-columns-spanned="4">
            <fo:block start-indent="0.2in">
                <xsl:value-of select="yname"/>
                <xsl:text>, pitched at </xsl:text>
                <xsl:apply-templates select="temperature"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
    <xsl:apply-templates select="starter"/>
    <xsl:apply-templates select="aeration"/>
    <xsl:apply-templates select="comment" mode="table-row"/>
</xsl:template>

<xsl:template match="starter">
    <fo:table-row>
        <fo:table-cell number-columns-spanned="4">
            <fo:block start-indent="0.2in">
              <xsl:text>Starter: </xsl:text>
              <xsl:value-of select="."/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

<xsl:template match="aeration">
    <fo:table-row>
        <fo:table-cell number-columns-spanned="4">
            <fo:block start-indent="0.2in">
              <xsl:text>Aeration: </xsl:text>
              <xsl:value-of select="."/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

<!-- OTHER INGREDIENTS -->
<xsl:template match="others">
    <fo:table-row>
        <fo:table-cell><fo:block line-height="2pt">&#160;</fo:block></fo:table-cell>
    </fo:table-row>
    <xsl:for-each select="other">
        <fo:table-row>
            <xsl:apply-templates select="weight"/>
            <xsl:apply-templates select="volume"/>
            <fo:table-cell>
                <fo:block>
                    <xsl:value-of select="oname"/>
                    <xsl:text> (</xsl:text>
                    <xsl:apply-templates select="time"/>
                    <xsl:text>)</xsl:text>
                </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:for-each>
</xsl:template>

<!-- MASH -->
<xsl:template match="mash">
    <xsl:for-each select="step">
        <fo:list-item>
            <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
            <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
            <fo:list-item-body start-indent="0.1in">
                <fo:block>
                    <xsl:apply-templates select="added_water"/>
                    <xsl:apply-templates select="added_heat"/>
                    <xsl:apply-templates select="grist"/>
                    <xsl:apply-templates select="time" mode="step"/>
                    <xsl:apply-templates select="comment"/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:for-each>
</xsl:template>

<xsl:template match="added_water">
    <xsl:value-of select="volume"/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="volume/@type"/>
    <xsl:text> water @ </xsl:text>
    <xsl:apply-templates select="temperature"/>
</xsl:template>

<xsl:template match="added_heat">
    <xsl:text>Heated</xsl:text>
</xsl:template>

<xsl:template match="grist">
    <xsl:text>, grist ratio of </xsl:text>
    <xsl:value-of select="ratio"/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="ratio/@type"/>
    <xsl:text> @ </xsl:text>
    <xsl:apply-templates select="temperature"/>
</xsl:template>

<xsl:template match="ingredients/adjuncts/adjunct/comment">
    <fo:list-block>
        <fo:list-item>
            <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
            <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
            <fo:list-item-body start-indent="0.1in">
                <fo:block>
                    <xsl:value-of select="../aname"/>
                    <xsl:text>: </xsl:text>
                    <xsl:value-of select="."/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </fo:list-block>
</xsl:template>

<!-- SPARGE -->
<xsl:template match="sparge">
    <xsl:for-each select="step">
        <fo:list-item>
            <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
            <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
            <fo:list-item-body start-indent="0.1in">
                <fo:block>
                    <xsl:apply-templates select="added_water"/>
                    <xsl:text>, drain</xsl:text>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:for-each>
    <xsl:apply-templates select="comment" mode="li"/>
</xsl:template>

<!-- BOIL -->
<xsl:template match="boil">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:text>Boiled </xsl:text>
                <xsl:apply-templates select="start/volume" mode="notable"/>
                <xsl:text> for </xsl:text>
                <xsl:apply-templates select="time"/>
                <xsl:text> to yield </xsl:text>
                <xsl:apply-templates select="end/volume" mode="notable"/>
                <xsl:text> wort</xsl:text>
                <!-- <xsl:apply-templates select="comment" mode="paren"/> -->
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
    <xsl:apply-templates select="comment" mode="li"/>
</xsl:template>

<!-- FERMENTATION -->
<xsl:template match="fermentation">
    <xsl:apply-templates select="primary"/>
    <xsl:apply-templates select="secondary"/>
    <xsl:apply-templates select="comment" mode="li"/>
</xsl:template>

<xsl:template match="primary">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:text>Primary: </xsl:text>
                <xsl:value-of select="@type"/>
                <xsl:text>, </xsl:text>
                <xsl:apply-templates select="time"/>
                <xsl:text>, </xsl:text>
                <xsl:apply-templates select="temperature"/>
                <xsl:apply-templates select="comment"/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<xsl:template match="secondary">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:text>Secondary: </xsl:text>
                <xsl:value-of select="@type"/>
                <xsl:text>, </xsl:text>
                <xsl:apply-templates select="time"/>
                <xsl:text>, </xsl:text>
                <xsl:apply-templates select="temperature"/>
                <xsl:apply-templates select="comment"/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<!-- PACKAGING -->
<xsl:template match="packaging">
    <xsl:apply-templates select="bottling"/>
    <xsl:apply-templates select="kegging"/>
    <xsl:apply-templates select="time" mode="conditioning"/>
    <xsl:apply-templates select="ready"/>
</xsl:template>

<!-- BOTTLING -->
<xsl:template match="bottling">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:text>Bottled with </xsl:text>
                <xsl:apply-templates select="weight" mode="notable"/>
                <xsl:apply-templates select="volume" mode="notable"/>
                <!-- <xsl:text>&#160;</xsl:text> -->
                <xsl:text> </xsl:text>
                <xsl:value-of select="sugar"/>
                <xsl:apply-templates select="comment"/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<!-- KEGGING -->
<xsl:template match="kegging">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:apply-templates select="force_carb"/>
                <xsl:apply-templates select="primed"/>
                <xsl:apply-templates select="comment"/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<!-- FORCE_CARB -->
<xsl:template match="force_carb">
    <xsl:text>Kegged at </xsl:text>
    <xsl:value-of select="psi"/>
    <xsl:text> psi, </xsl:text>
    <xsl:apply-templates select="temperature"/>
    <xsl:text> (</xsl:text>
    <xsl:value-of select="volumes"/>
    <xsl:text> volumes CO</xsl:text>
    <fo:inline font-size="0.75em" baseline-shift="sub">2</fo:inline>
    <xsl:text>)</xsl:text>
    <xsl:apply-templates select="comment"/>
</xsl:template>

<!-- PRIMED -->
<xsl:template match="primed">
    <xsl:text>Kegged with </xsl:text>
    <xsl:apply-templates select="weight" mode="notable"/>
    <xsl:apply-templates select="volume" mode="notable"/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="sugar"/>
    <xsl:apply-templates select="comment"/>
</xsl:template>

<!-- READY -->
<xsl:template match="ready">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:text>Ready to drink on </xsl:text>
                <xsl:value-of select="."/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<!-- DATA -->
<xsl:template match="predicted_data">
    <fo:table-row>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Starting Gravity: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:value-of select="../actual_data/SG"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Final Gravity: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:value-of select="../actual_data/FG"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
    <fo:table-row>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Original Extract: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:value-of select="../actual_data/OE"/>
                <xsl:text>&#176;Plato</xsl:text>
                <!-- <xsl:text>&#160;degrees&#160;plato</xsl:text> -->
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Apparent Extract: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:value-of select="../actual_data/AE"/>
                <xsl:text>&#176;Plato</xsl:text>
                <!-- <xsl:text>&#160;degrees&#160;plato</xsl:text> -->
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
    <fo:table-row>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Alcohol: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:value-of select="../actual_data/ABV"/>
                <xsl:text>% by volume</xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Alcohol: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:text></xsl:text>
                <xsl:value-of select="../actual_data/ABW"/>
                <xsl:text>% by weight</xsl:text>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
    <fo:table-row>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Apparent Attenuation: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:value-of select="../actual_data/AA"/>
                <xsl:text>%</xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Mash Efficiency: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:value-of select="../actual_data/efficiency"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
    <fo:table-row>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Bitterness: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:apply-templates select="bitterness"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block text-align="right">
                <xsl:text>Color: </xsl:text>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block>
                <xsl:apply-templates select="color"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

<xsl:template match="bitterness">
    <xsl:value-of select="."/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="./@type"/>
</xsl:template>

<xsl:template match="color">
    <xsl:value-of select="."/>
    <xsl:text>&#176;</xsl:text>
    <xsl:value-of select="./@type"/>
</xsl:template>

<!-- BREWING NOTES -->
<xsl:template match="brewing_notes">
    <fo:block
        font-family="bold" font-size="9pt"
        space-before="2pt" space-after="1pt">
        <xsl:text>Brewing Notes</xsl:text>
    </fo:block>
    <fo:list-block
        font-family="rm" font-size="9pt">
        <xsl:apply-templates select="note"/>
    </fo:list-block>
</xsl:template>

<!-- TASTING NOTES -->
<xsl:template match="tasting_notes">
    <fo:block
        font-family="bold" font-size="9pt"
        space-before="2pt" space-after="1pt">
        <xsl:text>Tasting Notes</xsl:text>
    </fo:block>
    <fo:list-block
        font-family="rm" font-size="9pt">
        <xsl:apply-templates select="note"/>
    </fo:list-block>
</xsl:template>

<!-- NOTE -->
<xsl:template match="note">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:value-of select="."/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<!-- COMMENTS -->
<xsl:template match="comment" mode="list-block">
    <fo:block
        font-family="bold" font-size="9pt"
        space-before="2pt" space-after="1pt">
        <xsl:text>Tasting Notes</xsl:text>
    </fo:block>
    <fo:list-block
        font-family="rm" font-size="9pt">
        <fo:list-item>
            <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
            <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
            <fo:list-item-body start-indent="0.1in">
                <fo:block>
                    <xsl:value-of select="."/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </fo:list-block>
</xsl:template>

<!-- COMMENT -->
<xsl:template match="comment">
    <xsl:text>, </xsl:text>
    <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="comment" mode="nocomma">
  <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="comment" mode="paren">
  <xsl:text> (</xsl:text>
  <xsl:value-of select="."/>
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="comment" mode="table-row">
    <fo:table-row>
        <fo:table-cell number-columns-spanned="4">
            <fo:block start-indent="0.2in">
              <xsl:text>(</xsl:text>
              <xsl:value-of select="."/>
              <xsl:text>)</xsl:text>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

<xsl:template match="comment" mode="adjunct_ref">
  <xsl:text>(see notes below)</xsl:text>
</xsl:template>

<xsl:template match="comment" mode="li">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:value-of select="."/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<!-- GENERIC TEMPLATES -->
<xsl:template match="weight">
    <fo:table-cell 
        padding-right="5pt" text-align="right">
        <fo:block start-indent="0.2in">
            <xsl:value-of select="."/>
        </fo:block>
    </fo:table-cell>
    <fo:table-cell>
        <fo:block>
            <xsl:value-of select="@type"/>
        </fo:block>
    </fo:table-cell>
    <fo:table-cell>
        <fo:block>
            <xsl:text> </xsl:text>
        </fo:block>
    </fo:table-cell>
</xsl:template>

<xsl:template match="weight" mode="with-percentage">
    <fo:table-cell 
        padding-right="5pt" text-align="right">
        <fo:block start-indent="0.2in">
            <xsl:value-of select="."/>
        </fo:block>
    </fo:table-cell>
    <fo:table-cell>
        <fo:block>
            <xsl:value-of select="@type"/>
        </fo:block>
    </fo:table-cell>
    <fo:table-cell
        padding-right="7pt" text-align="right">
        <fo:block>
            <xsl:apply-templates select="../percentage"/>
        </fo:block>
    </fo:table-cell>
</xsl:template>

<xsl:template match="weight" mode="notable">
    <xsl:value-of select="."/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="@type"/>
</xsl:template>

<xsl:template match="volume">
    <fo:table-cell
        padding-right="5pt" text-align="right">
        <fo:block>
            <xsl:value-of select="."/>
        </fo:block>
    </fo:table-cell>
    <fo:table-cell>
        <fo:block>
            <xsl:value-of select="@type"/>
        </fo:block>
    </fo:table-cell>
    <fo:table-cell>
        <fo:block>
            <xsl:text> </xsl:text>
        </fo:block>
    </fo:table-cell>
</xsl:template>

<xsl:template match="volume" mode="notable">
    <xsl:value-of select="."/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="@type"/>
</xsl:template>

<xsl:template match="volume" mode="minus_half">
    <xsl:value-of select="number(.) - 0.5"/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="@type"/>
</xsl:template>

<xsl:template match="time">
    <xsl:value-of select="."/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="@type"/>
</xsl:template>

<xsl:template match="time" mode="paren">
    <xsl:text>(</xsl:text>
    <xsl:value-of select="."/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="@type"/>
    <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="time" mode="step">
    <xsl:text> (Held </xsl:text>
    <xsl:value-of select="."/>
    <!-- <xsl:text>&#160;</xsl:text> -->
    <xsl:text> </xsl:text>
    <xsl:value-of select="@type"/>
    <xsl:text>)</xsl:text>
</xsl:template>
  
<xsl:template match="time" mode="conditioning">
    <fo:list-item>
        <!-- <fo:list-item-label><fo:block>&#160;</fo:block></fo:list-item-label> -->
        <fo:list-item-label><fo:block>&#x2022;</fo:block></fo:list-item-label>
        <fo:list-item-body start-indent="0.1in">
            <fo:block>
                <xsl:text>Conditioned for </xsl:text>
                <xsl:value-of select="."/>
                <xsl:text> </xsl:text>
                <xsl:value-of select="@type"/>
            </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</xsl:template>

<xsl:template match="temperature">
    <xsl:value-of select="."/>
    <xsl:text>&#176;</xsl:text>
    <!-- <xsl:text> degrees </xsl:text> -->
    <xsl:value-of select="./@type"/>
</xsl:template>

<xsl:template match="percentage">
    <xsl:text>(</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>%)</xsl:text>
</xsl:template>

</xsl:stylesheet>
