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

<xsl:output method="xml" indent="yes"/>

<!-- output the fo header for the root element -->
<xsl:template match="bracket">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <!-- defines the layout master -->
  <fo:layout-master-set>
    <fo:simple-page-master master-name="print" 
                           page-height="11in" 
                           page-width="8.5in" 
                           margin-top="0in" 
                           margin-bottom="0.5in" 
                           margin-left="0.25in" 
                           margin-right="0.25in">
		<fo:region-body />
    </fo:simple-page-master>
  </fo:layout-master-set>

  <!-- starts actual layout -->
  <fo:page-sequence master-name="print">
		<fo:flow flow-name="xsl-region-body">
			<xsl:apply-templates />
		</fo:flow>
	</fo:page-sequence>
</fo:root>
</xsl:template>

<!-- 
    the break-after is in a separate block, since
	putting it in block-container has no effect
-->
<xsl:template match="page">
	<fo:block-container font-family="sans-serif" font-size="8pt">
		<xsl:apply-templates />
	</fo:block-container>
	<fo:block break-after="page" />
</xsl:template>

<!-- generate all cells for each line of the bracket -->
<xsl:template match="line">
	<xsl:for-each select="cell">
	<fo:block-container position="absolute">
		<xsl:attribute name="top"><xsl:value-of select="../@num * 0.15"/>in</xsl:attribute>
		<xsl:attribute name="left"><xsl:value-of select="@num * 1"/>in</xsl:attribute>
		<xsl:attribute name="bottom"><xsl:value-of select="(../@num + 1) * 0.15"/>in</xsl:attribute>
		<xsl:attribute name="right"><xsl:value-of select="(@num + 1) * 1"/>in</xsl:attribute>

	<!-- turn on right border to simulate a vertical bar -->
	<xsl:if test="@vbar = 'yes'">
		<xsl:attribute name="border-right-width">1px</xsl:attribute>
		<xsl:attribute name="border-right-style">solid</xsl:attribute>
		<xsl:attribute name="border-right-color">black</xsl:attribute>
	</xsl:if>
	
	<!-- turn on bottom border to simulate underlining -->
	<xsl:if test="@underline = 'yes'">
		<xsl:attribute name="border-bottom-width">1px</xsl:attribute>
		<xsl:attribute name="border-bottom-style">solid</xsl:attribute>
		<xsl:attribute name="border-bottom-color">black</xsl:attribute>
	</xsl:if>
	
	<!-- the start-indent keeps the text from bumping against
	     vertical bars; the space-before moves the text down
		 to the underline -->
	<fo:block start-indent="2pt" space-before="2pt" wrap-option="no-wrap">
		<xsl:apply-templates />
	</fo:block>
	</fo:block-container>
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
