<?xml version="1.0" encoding="iso-8859-1"?>

<!-- This stylesheet formats the questions file for conversion to a pdf -->
<!-- Author: Fernando Paulo -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
    exclude-result-prefixes="xalan" xmlns:xalan="http://xml.apache.org/xslt" >

    <xsl:output encoding="UTF-8" indent="yes" method="xml" xalan:indent-amount="2"/>

    <!-- matches the root element -->
    <xsl:template match="/">
        <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master master-name="project">
                <fo:region-body margin="1in"/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="project">
            <fo:flow flow-name="xsl-region-body" font-size="14pt" font-family="Times">
                <xsl:apply-templates/>
            </fo:flow>
        </fo:page-sequence>
        </fo:root>
    </xsl:template>
    
    <!-- matches the top level header of the questions file -->
    <xsl:template match="questions">
        <fo:block font-size="18pt" text-align="center" border-after-width="1pt" border-after-style="double" 
            border-after-color="#000000" space-before="30pt" space-before.conditionality="retain" 
            space-after="12pt">CSCIE-259 - Project <xsl:value-of select="@project"/> (version <xsl:value-of select="@version"/>)
            <fo:block font-size="16pt" font-style="italic" >Author: <xsl:value-of select="@author"/></fo:block>
        </fo:block>
        <xsl:apply-templates select="child::*"/>
    </xsl:template>
    
    
    <!-- matches question, putting the question number in bold -->
    <xsl:template match="question">
        <fo:block padding-before="10pt" padding-after="30pt">
            <fo:inline font-weight="bold">Question <xsl:value-of select="@id"/>)</fo:inline>
            <xsl:apply-templates select="child::*"/>
        </fo:block>
    </xsl:template>
    
    <!-- matches an answer, putting the answer number in bold -->
    <xsl:template match="answer">
        <fo:block text-indent="20pt" padding-before="5pt"><fo:inline font-weight="bold"><xsl:value-of select="@id"/>)</fo:inline>
            <xsl:apply-templates select="child::node()"/>
        </fo:block>
    </xsl:template>
    
    <!-- use a different font for code fragemnts, similar to the CODE tag in html -->
    <xsl:template match="code">
        <fo:inline font-family="Courier"><xsl:value-of select="."/></fo:inline>
    </xsl:template>

</xsl:stylesheet>
    