<?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">
  <!-- Begin Attributes -->
  <xsl:attribute-set name="contentFont">
    <xsl:attribute name="font-size">10pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
    <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="contentFontWrap">
    <xsl:attribute name="font-size">10pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
    <xsl:attribute name="wrap-option">wrap</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="contentBoldFont">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">9pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="titleFont">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">18pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="headerFontLarge">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">14pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="headerFont">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">12pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="subHeaderFont">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">10pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="labelFont">
    <xsl:attribute name="font-size">10pt</xsl:attribute>
    <xsl:attribute name="font-family">Time</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="pageFont">
    <xsl:attribute name="font-size">7pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="footFont">
    <xsl:attribute name="font-size">8pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="miscFont">
    <xsl:attribute name="font-style">italic</xsl:attribute>
    <xsl:attribute name="font-size">7pt</xsl:attribute>
    <xsl:attribute name="font-family">Times</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="dreesLogo">
    <xsl:attribute name="src">
      <xsl:choose>
        <xsl:when test="CONTRACT_INFO/DIV_ID=105">/contracts/pdfsets/mddocuments/dreambuilder/images/marquislogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=109">/contracts/pdfsets/mddocuments/dreambuilder/images/marquislogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=110">/contracts/pdfsets/mddocuments/dreambuilder/images/marquislogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=210">/contracts/pdfsets/mddocuments/dreambuilder/images/zaringlogosmall.jpg</xsl:when>
		<xsl:when test="CONTRACT_INFO/DIV_ID=214">/contracts/pdfsets/mddocuments/dreambuilder/images/zaringlogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=123">/contracts/pdfsets/mddocuments/dreambuilder/images/dreescustomlogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=124">/contracts/pdfsets/mddocuments/dreambuilder/images/dreescustomlogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=125">/contracts/pdfsets/mddocuments/dreambuilder/images/dreescustomlogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=105">/contracts/pdfsets/mddocuments/dreambuilder/images/marquislogosmall.jpg</xsl:when>
        <xsl:when test="CONTRACT_INFO/DIV_ID=936">/contracts/pdfsets/mddocuments/dreambuilder/images/hmblogosmall.jpg</xsl:when>
        <xsl:otherwise>/contracts/pdfsets/mddocuments/dreambuilder/images/dreeslogosmall.jpg</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name="ehoLogo">
    <xsl:attribute name="src">/contracts/pdfsets/mddocuments/dreambuilder/images/ehobw.jpg</xsl:attribute>
  </xsl:attribute-set>
  <!-- End Attributes -->

  <!-- Begin Templates -->
  <xsl:template match="/CONTRACT">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <!-- defines the layout master -->
      <!-- this will determine the dimensions of the pdf document -->
      <fo:layout-master-set>
        <!-- layout for the first page -->
        <fo:simple-page-master master-name="first" page-height="35.56cm" page-width="21cm"
          margin-bottom="0cm" margin-left="0cm" margin-right="0cm" margin-top="1cm">
          <fo:region-body margin-left="1cm" margin-top="3cm" margin-bottom="1.5cm"
            margin-right="1cm"/>
          <fo:region-before region-name="header-first" extent="3cm"/>
          <fo:region-after extent="1.5cm"/>
        </fo:simple-page-master>

        <!-- layout for the other page -->
        <fo:simple-page-master master-name="rest" page-height="35.56cm" page-width="21cm"
          margin-bottom="0cm" margin-left="0cm" margin-right="0cm" margin-top="1cm">
          <fo:region-body margin-left="1cm" margin-top="3cm" margin-bottom="1.5cm"
            margin-right="1cm"/>
          <fo:region-before region-name="header-rest" extent="3cm"/>
          <fo:region-after extent="1.5cm"/>
        </fo:simple-page-master>

        <fo:page-sequence-master master-name="firstAndRest">
          <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="first" page-position="first"/>
            <fo:conditional-page-master-reference master-reference="rest" page-position="rest"/>
            <!-- recommended fallback procedure -->
            <fo:conditional-page-master-reference master-reference="rest"/>
          </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>

      </fo:layout-master-set>
      <!-- end: defines page layout -->

      <!-- starts actual layout -->
      <fo:page-sequence master-reference="firstAndRest">
        <fo:static-content flow-name="header-first">
          <fo:block text-align="center" xsl:use-attribute-sets="titleFont"
            space-before.optimum="1.5cm">Selection Sheet</fo:block>
        </fo:static-content>
        <fo:static-content flow-name="header-rest">
          <fo:block text-align="center" xsl:use-attribute-sets="titleFont"
            space-before.optimum="1.5cm">Selection Sheet</fo:block>
          <fo:block text-align="right" end-indent="1cm" xsl:use-attribute-sets="labelFont"
            space-before.optimum="-0.3cm">
            <xsl:value-of select="SELECTION_DATA/@SH_JOB_ID"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="SELECTION_DATA/@SH_PLAN"/>
            <xsl:text> - </xsl:text>
            <xsl:value-of select="SELECTION_DATA/@SH_ELEVATION"/>
          </fo:block>
        </fo:static-content>
        <!-- this defines the footer information -->
        <fo:static-content flow-name="xsl-region-after" space-before="0.25cm">
          <fo:block text-align="left" start-indent="1cm" xsl:use-attribute-sets="footFont"
            space-before.optimum="0.1cm">Distribution: Builder, Job, Sales, Market Manager,
            Purchaser</fo:block>
          <fo:block text-align="center" xsl:use-attribute-sets="pageFont"
            space-before.optimum="-0.3cm">Page <fo:page-number/> of <fo:page-number-citation
              ref-id="lastPage"/></fo:block>
          <fo:block text-align="right" end-indent="1cm" xsl:use-attribute-sets="miscFont"
            space-before.optimum="-0.3cm">
            <xsl:value-of select="SELECTION_DATA/@creationDate"/>
          </fo:block>
          <fo:block text-align="right" xsl:use-attribute-sets="footFont"
            space-before.optimum="0.1cm" space-after.optimum="1cm" end-indent="1cm" >
            <xsl:text>CUSTOMER INITIALS ___________</xsl:text>
          </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
          <fo:block text-align="left" start-indent="0cm" space-before.optimum="-2cm"
            space-after.optimum="0.5cm">
            <fo:external-graphic  xsl:use-attribute-sets="dreesLogo"/>
          </fo:block>
          <xsl:apply-templates select="SELECTION_DATA"/>
          <fo:block break-before="page"/>
          <xsl:apply-templates select="SELECTION_DATA" mode="sum"/>
          <fo:block text-align="left" xsl:use-attribute-sets="subHeaderFont"
            space-before.optimum="0.5cm" space-after.optimum="0.3cm">
            <xsl:text>
BY HIS/HER SIGNATURE, PURCHASER ACKNOWLEDGES THAT THE OPTIONS SELECTED AND THEIR CORRESPONDING 
</xsl:text>
            <xsl:text>
CHARGES NOTED ON THE SELECTION SHEETS IN THE "PRICE AGREEMENT" COLUMN ARE A PART OF THE DREES 
</xsl:text>
            <xsl:text>
COMPANY CONSTRUCTION AND PURCHASE AGREEMENT. THIS IS A LEGALLY BINDING CONTRACT. READ AND UNDERSTAND 
</xsl:text>
            <xsl:text>
ALL PROVISIONS PRIOR TO SIGNING. IF NOT UNDERSTOOD, SEEK LEGAL ADVICE.
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont" space-after.optimum="0.3cm">
            <xsl:text>
THE WRITTEN CONSTRUCTION AND PURCHASE AGREEMENT AND ADDENDUM(S) CONTAIN THE ENTIRE AGREEMENT 
</xsl:text>
            <xsl:text>
BETWEEN THE PARTIES. NO AGENT OR EMPLOYEE OF THE BUILDER HAS ANY AUTHORITY TO CHANGE OR ORALLY 
</xsl:text>
            <xsl:text>
MODIFY THE TERMS AND CONDITIONS OF THE CONSTRUCTION AND PURCHASE AGREEMENT OR ADDENDUM(S), AND 
</xsl:text>
            <xsl:text>
YOU SHOULD RELY ONLY UPON THE TERMS AND CONDITIONS OF THE WRITTEN CONSTRUCTION AND PURCHASE AGREEMENT 
</xsl:text>
            <xsl:text>
AND ADDENDUM(S) REGARDING YOUR LEGAL RIGHTS THERE UNDER.
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont">
            <xsl:text>
PURCHASER SIGNATURE _____________________________________________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont" space-after.optimum="0.3cm">
            <xsl:text>
DATE ____________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont">
            <xsl:text>
PURCHASER SIGNATURE _____________________________________________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont" space-after.optimum="0.3cm">
            <xsl:text>
DATE ____________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont">
            <xsl:text>
PURCHASER'S PHONE NUMBER (HOME) _(_____)_________________________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont" space-after.optimum="0.3cm">
            <xsl:text>
(WORK) _(_____)_________________________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont">
            <xsl:text>
DESIGN CONSULTANT'S SIGNATURE ___________________________________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont" space-after.optimum="0.3cm">
            <xsl:text>
SALES SECRETARY INITIALS ___________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont">
            <xsl:text>
SELECTION DATE _____________________
</xsl:text>
          </fo:block>
          <fo:block text-align="left" xsl:use-attribute-sets="labelFont">
            <xsl:text>
DESIGN CENTER PHONE # _(_____)___________________________________________
</xsl:text>
          </fo:block>
          <fo:block id="lastPage"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
  <xsl:template match="SELECTION_DATA">
    <fo:table table-layout="fixed" padding-left="15pt" padding-right="15pt">
      <fo:table-column column-width="1.5cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.6cm"/>
      <fo:table-column column-width="1.5cm"/>
      <fo:table-body>
        <fo:table-row height="0.7cm">
          <fo:table-cell number-columns-spanned="12">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Purchaser(s): <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="/CONTRACT/CONTRACT_INFO/COMBINED_LEGAL_NAME"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="1.5cm" leader-pattern="space"/>
              <fo:leader leader-length="17.2cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <fo:table-row height="0.7cm">
          <fo:table-cell number-columns-spanned="4">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Job Number : <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="@SH_JOB_ID"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="2cm" leader-pattern="space"/>
              <fo:leader leader-length="4.0cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell number-columns-spanned="4">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Phone 1: <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="/CONTRACT/CONTRACT_INFO/BUYER_PHONE1"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="2cm" leader-pattern="space"/>
              <fo:leader leader-length="4.1cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell number-columns-spanned="4">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Phone 2: <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="/CONTRACT/CONTRACT_INFO/BUYER_PHONE2"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="2cm" leader-pattern="space"/>
              <fo:leader leader-length="4.0cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <fo:table-row height="0.7cm">
          <fo:table-cell number-columns-spanned="6">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Address: <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="@ADDRESS"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="1.5cm" leader-pattern="space"/>
              <fo:leader leader-length="7.7cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell number-columns-spanned="6">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Community: <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="/CONTRACT/CONTRACT_INFO/nb_name"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="2cm" leader-pattern="space"/>
              <fo:leader leader-length="7.2cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <fo:table-row height="0.7cm">
          <fo:table-cell number-columns-spanned="6">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Home - Elevation :
                <fo:leader leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="@SH_PLAN"/>- <xsl:value-of select="@SH_ELEVATION"/>
              </fo:inline>
            </fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="2.8cm" leader-pattern="space"/>
              <fo:leader leader-length="6.4cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell number-columns-spanned="3">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Plan Code: <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="@SH_PLAN_CODE"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="1.7cm" leader-pattern="space"/>
              <fo:leader leader-length="2.8cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell number-columns-spanned="3">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Contract Date: <fo:leader
                leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="/CONTRACT/CONTRACT_INFO/CONTRACT_SIGNED_DATE"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="2.2cm" leader-pattern="space"/>
              <fo:leader leader-length="2.2cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <fo:table-row height="0.7cm">
          <fo:table-cell number-columns-spanned="6">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Design Center Contact :
                <fo:leader leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="DesignContactName"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="3.5cm" leader-pattern="space"/>
              <fo:leader leader-length="5.7cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell number-columns-spanned="6">
            <fo:block xsl:use-attribute-sets="labelFont" text-align="left">Market Manager :
                <fo:leader leader-length="2pt" leader-pattern="space"/>
              <fo:inline xsl:use-attribute-sets="contentFont">
                <xsl:value-of select="/CONTRACT/CONTRACT_INFO/MKT_MGR_NAME"/>
              </fo:inline></fo:block>
            <fo:block space-before.optimum="-0.3cm">
              <fo:leader leader-length="2.5cm" leader-pattern="space"/>
              <fo:leader leader-length="6.7cm" leader-pattern="rule" rule-thickness="0.1mm"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
    <xsl:apply-templates select="CATEGORY[SUBCATEGORY/OPTIONS]" mode="display"/>
  </xsl:template>

  <xsl:template match="CATEGORY[SUBCATEGORY/OPTIONS]" mode="display">
    <fo:block text-align="left" line-height="0.8cm" border-style="solid" border-width="0.1mm"
      xsl:use-attribute-sets="headerFontLarge" background-color="#C0C0C0"
      space-after.optimum="0.2cm">
      <xsl:value-of select="@CAT_DESC"/>
    </fo:block>
    <xsl:apply-templates select="SUBCATEGORY"/>
    <xsl:if test="position() != last()">
      <!--<fo:block break-before="page"/>-->
    </xsl:if>
  </xsl:template>

  <xsl:template match="SUBCATEGORY[OPTIONS]">
    <xsl:variable name="temp1" select="@subcat_desc"/>
    <xsl:variable name="temp2" select="@style"/>
    <xsl:variable name="temp3" select="@make_model"/>
    <xsl:variable name="temp4" select="@manufacturer"/>
    <xsl:variable name="temp5" select="@code"/>
    <xsl:variable name="temp6" select="@color"/>
    <xsl:variable name="temp7" select="@wood_species"/>
    <xsl:variable name="temp8" select="@wood_finsh"/>
    <fo:table table-layout="fixed" padding-left="15pt" padding-right="15pt">
      <fo:table-column column-width="1.5cm"/>
      <fo:table-column column-width="4.5cm"/>
      <fo:table-column column-width="2.5cm"/>
      <fo:table-column column-width="2.5cm"/>
      <fo:table-column column-width="2.5cm"/>
      <fo:table-column column-width="2.5cm"/>
      <fo:table-column column-width="3cm"/>
      <fo:table-body>
        <fo:table-row height="0.8cm" display-align="center">
          <fo:table-cell number-columns-spanned="7" background-color="#F2F2F2">
            <fo:block text-align="left" xsl:use-attribute-sets="headerFont">
              <xsl:value-of select="@subcat_desc"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <fo:table-row height="0.6cm" display-align="center">
          <xsl:variable name="temp" select="@quantity_flag"/>
          <xsl:choose>
            <xsl:when test="contains($temp1, '1') or contains($temp2, '1') or contains($temp3, '1') or contains($temp4, '1') or contains($temp5, '1') or contains($temp6, '1') or contains($temp7, '1') or contains($temp8, '1')">
              <xsl:choose>
                <xsl:when test="contains($temp, '1')">
                  <fo:table-cell border-style="solid" border-width="0.1mm">
                    <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                      line-height="0.6cm">QTY</fo:block>
                  </fo:table-cell>
                  <fo:table-cell border-style="solid" border-width="0.1mm">
                    <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                      line-height="0.6cm">SELECTION</fo:block>
                  </fo:table-cell>
                </xsl:when>
                <xsl:otherwise>
                  <fo:table-cell number-columns-spanned="2" border-style="solid"
                    border-width="0.1mm">
                    <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                      line-height="0.6cm">SELECTION</fo:block>
                  </fo:table-cell>
                </xsl:otherwise>
              </xsl:choose>
              <fo:table-cell border-style="solid" border-width="0.1mm">
                <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                  line-height="0.6cm">DESC.</fo:block>

              </fo:table-cell>
              <fo:table-cell border-style="solid" border-width="0.1mm">
                <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                  line-height="0.6cm">COLOR</fo:block>
              </fo:table-cell>
              <fo:table-cell border-style="solid" border-width="0.1mm">
                <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                  line-height="0.6cm">WOOD</fo:block>
              </fo:table-cell>
              <fo:table-cell border-style="solid" border-width="0.1mm">
                <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                  line-height="0.6cm">FINISH</fo:block>
              </fo:table-cell>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="contains($temp, '1')">
                  <fo:table-cell border-style="solid" border-width="0.1mm">
                    <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                      line-height="0.6cm">QTY</fo:block>
                  </fo:table-cell>
                  <fo:table-cell number-columns-spanned="5" border-style="solid"
                    border-width="0.1mm">
                    <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                      line-height="0.6cm">SELECTION</fo:block>
                  </fo:table-cell>
                </xsl:when>
                <xsl:otherwise>
                  <fo:table-cell number-columns-spanned="6" border-style="solid"
                    border-width="0.1mm">
                    <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont"
                      line-height="0.6cm">SELECTION</fo:block>
                  </fo:table-cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
          <fo:table-cell border-style="solid" border-width="0.1mm">
            <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont" line-height="0.6cm">OPTION PRICE</fo:block>
          </fo:table-cell>
        </fo:table-row>
        <xsl:apply-templates select="OPTIONS"/>
        <fo:table-row height="0.8cm" display-align="center">
          <fo:table-cell number-columns-spanned="6">
            <fo:block text-align="right" xsl:use-attribute-sets="headerFont">SubTotal</fo:block>
          </fo:table-cell>
          <fo:table-cell border-style="solid" border-width="0.1mm">
            <fo:block text-align="right" end-indent="4pt" xsl:use-attribute-sets="headerFont">$
              <xsl:value-of select="@SAprvdTotal"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <fo:table-row height="0.5cm">
          <fo:table-cell number-columns-spanned="7">
            <fo:block/>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>

  <xsl:template match="OPTIONS">
    <xsl:variable name="isJDE" select="@IsJde"/>
    <xsl:variable name="selPlOptionCode" select="@optionCode"/>
    <xsl:variable name="selAdjustmentNotAgreement" select="@selAdjustmentNotAgreement"/>
    <xsl:variable name="temp1" select="ancestor::SUBCATEGORY/@subcat_desc"/>
    <xsl:variable name="temp2" select="ancestor::SUBCATEGORY/@style"/>
    <xsl:variable name="temp3" select="ancestor::SUBCATEGORY/@make_model"/>
    <xsl:variable name="temp4" select="ancestor::SUBCATEGORY/@manufacturer"/>
    <xsl:variable name="temp5" select="ancestor::SUBCATEGORY/@code"/>
    <xsl:variable name="temp6" select="ancestor::SUBCATEGORY/@color"/>
    <xsl:variable name="temp7" select="ancestor::SUBCATEGORY/@wood_species"/>
    <xsl:variable name="temp8" select="ancestor::SUBCATEGORY/@wood_finish"/>
    <fo:table-row height="0.5cm" display-align="center">
      <!--<fo:table-cell number-columns-spanned="8">
        <fo:block>
        <xsl:value-of select="@itemName"/>
        </fo:block>
        </fo:table-cell>-->
      
      <xsl:variable name="temp" select="ancestor::SUBCATEGORY/@quantity_flag"/>
      <xsl:choose>
        <xsl:when
          test="contains($temp1, '1') or contains($temp2, '1') or contains($temp3, '1') or contains($temp4, '1') or contains($temp5, '1') or contains($temp6, '1') or contains($temp7, '1') or contains($temp8, '1')">
          <xsl:choose>
            <xsl:when test="contains($temp, '1')">
              <fo:table-cell border-style="solid" border-width="0.1mm">
                <fo:block text-align="center" start-indent="1mm"
                  xsl:use-attribute-sets="contentFontWrap">
                  <xsl:value-of select="@adjustedQuantity"/>
                </fo:block>
              </fo:table-cell>
              <fo:table-cell border-style="solid" border-width="0.1mm">
                <fo:block/>


                  <xsl:if test="string-length($selPlOptionCode) &gt; 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">
                      <xsl:value-of select="@optionCode"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="@itemName"/>
                    </fo:block>
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentFontWrap">
                      <xsl:value-of select="SelOptionDescription"/>
                    </fo:block>
                  </xsl:if>

                  <xsl:if test="string-length($selPlOptionCode) = 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">CUSTOM OPTION: <xsl:value-of select="@itemName"/></fo:block>
                  </xsl:if>
                <xsl:if test="string-length(@note) &gt; 0">
                  <fo:block text-align="left" start-indent="1mm"
                    xsl:use-attribute-sets="contentFontWrap">
                    <xsl:value-of select="@note"/>
                  </fo:block>
                </xsl:if>


              </fo:table-cell>
            </xsl:when>
            <xsl:otherwise>
              <fo:table-cell number-columns-spanned="2" border-style="solid" border-width="0.1mm">
                  <xsl:if test="string-length($selPlOptionCode) &gt; 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">
                      <xsl:value-of select="@optionCode"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="@itemName"/>
                    </fo:block>
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentFontWrap">
                      <xsl:value-of select="SelOptionDescription"/>
                    </fo:block>
                  </xsl:if>

                  <xsl:if test="string-length($selPlOptionCode) = 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">CUSTOM OPTION: <xsl:value-of select="@itemName"/></fo:block>
                  </xsl:if>
                <xsl:if test="string-length(@note) &gt; 0">
                  <fo:block text-align="left" start-indent="1mm"
                    xsl:use-attribute-sets="contentFontWrap">
                    <xsl:value-of select="@note"/>
                  </fo:block>
                </xsl:if>
                <fo:block/>
              </fo:table-cell>
            </xsl:otherwise>
          </xsl:choose>
          <fo:table-cell border-style="solid" border-width="0.1mm">
            <xsl:if test="contains($temp1, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="SelDescription"/>
              </fo:block>
            </xsl:if>
            <xsl:if test="contains($temp2, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@style"/>
              </fo:block>
            </xsl:if>
            <xsl:if test="contains($temp3, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@make_model"/>
              </fo:block>
            </xsl:if>
            <xsl:if test="contains($temp4, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@manufacturer"/>
              </fo:block>
            </xsl:if>
            <xsl:if test="contains($temp5, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@code"/>
              </fo:block>
            </xsl:if>
            <fo:block/>
          </fo:table-cell>
          <fo:table-cell border-style="solid" border-width="0.1mm">
            <xsl:if test="contains($temp6, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@color_name"/>
              </fo:block>
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@color_id"/>
              </fo:block>
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@color_mfg"/>
              </fo:block>
            </xsl:if>
            <fo:block/>
          </fo:table-cell>
          <fo:table-cell border-style="solid" border-width="0.1mm">
            <xsl:if test="contains($temp7, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@wood_species"/>
              </fo:block>
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@wood_species_id"/>
              </fo:block>
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@wood_species_mfg"/>
              </fo:block>
            </xsl:if>
            <fo:block/>
          </fo:table-cell>
          <fo:table-cell border-style="solid" border-width="0.1mm">
            <xsl:if test="contains($temp8, '1')">
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@wood_finish"/>
              </fo:block>
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@wood_finish_id"/>
              </fo:block>
              <fo:block text-align="left" xsl:use-attribute-sets="contentFontWrap">
                <xsl:value-of select="@wood_finish_mfg"/>
              </fo:block>
            </xsl:if>
            <fo:block/>
          </fo:table-cell>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="contains($temp, '1')">
              <fo:table-cell border-style="solid" border-width="0.1mm">
                <fo:block text-align="center" start-indent="1mm"
                  xsl:use-attribute-sets="contentFontWrap">
                  <xsl:value-of select="@adjustedQuantity"/>
                </fo:block>
              </fo:table-cell>
              <fo:table-cell number-columns-spanned="5" border-style="solid" border-width="0.1mm">
                  <xsl:if test="string-length($selPlOptionCode) &gt; 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">
                      <xsl:value-of select="@optionCode"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="@itemName"/>
                    </fo:block>
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentFontWrap">
                      <xsl:value-of select="SelOptionDescription"/>
                    </fo:block>
                  </xsl:if>

                  <xsl:if test="string-length($selPlOptionCode) = 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">CUSTOM OPTION: <xsl:value-of select="@itemName"/></fo:block>
                  </xsl:if>
                <xsl:if test="string-length(@note) &gt; 0">
                  <fo:block text-align="left" start-indent="1mm"
                    xsl:use-attribute-sets="contentFontWrap">
                    <xsl:value-of select="@note"/>
                  </fo:block>
                </xsl:if>
                <fo:block/>
              </fo:table-cell>
            </xsl:when>
            <xsl:otherwise>
              <fo:table-cell number-columns-spanned="6" border-style="solid" border-width="0.1mm">
                  <xsl:if test="string-length($selPlOptionCode) &gt; 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">
                      <xsl:value-of select="@optionCode"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="@itemName"/>
                    </fo:block>
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentFontWrap">
                      <xsl:value-of select="SelOptionDescription"/>
                    </fo:block>
                  </xsl:if>

                  <xsl:if test="string-length($selPlOptionCode) = 0">
                    <fo:block text-align="left" start-indent="1mm" xsl:use-attribute-sets="contentBoldFont">CUSTOM OPTION: <xsl:value-of select="@itemName"/></fo:block>
                  </xsl:if>
                <xsl:if test="string-length(@note) &gt; 0">
                  <fo:block text-align="left" start-indent="1mm"
                    xsl:use-attribute-sets="contentFontWrap">
                    <xsl:value-of select="@note"/>
                  </fo:block>
                </xsl:if>
                <fo:block/>
              </fo:table-cell>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <fo:table-cell border-style="solid" border-width="0.1mm">
        <fo:block text-align="right" end-indent="4pt" xsl:use-attribute-sets="contentFont">
          $ <xsl:value-of select="@selectionTotal"/>
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>

  <xsl:template match="SELECTION_DATA" mode="sum">
    <fo:block text-align="center"  xsl:use-attribute-sets="headerFontLarge" space-before.optimum="0.7cm" space-after.optimum="0.1cm" page-break-inside="avoid"> Summary </fo:block>
    
    <fo:table table-layout="fixed" padding-left="15pt" padding-right="15pt" >
      <fo:table-column column-width="6cm"/>
      <fo:table-column column-width="4.5cm"/>
      <fo:table-column column-width="4.5cm"/>
      <fo:table-column column-width="4cm"/>   
      <fo:table-body>               
        <fo:table-row height="0.7cm">         
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont" line-height="0.6cm" >
              
            </fo:block>
          </fo:table-cell>
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont" line-height="0.6cm" >
              PRICE IN AGREEMENT
            </fo:block>
          </fo:table-cell>
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont" line-height="0.6cm" color="#CC0000">
              DIFFERENCE
            </fo:block>
          </fo:table-cell>
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="center" xsl:use-attribute-sets="subHeaderFont" line-height="0.6cm">
              TOTAL OPTION PRICE 
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <xsl:apply-templates select="CATEGORY[SUBCATEGORY]" mode="sum"/>
        
        <fo:table-row height="0.7cm">         
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
             <fo:block text-align="right" xsl:use-attribute-sets="headerFont" line-height="0.6cm" >
              BASE PRICE:
            </fo:block>
          </fo:table-cell>
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="right" end-indent="4pt" xsl:use-attribute-sets="headerFontLarge" line-height="0.6cm">
              $<xsl:value-of select="@SH_BASE_SALES_PRICE"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
        <fo:table-row height="0.7cm">         
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="right" xsl:use-attribute-sets="headerFont" line-height="0.6cm" >
              TOTAL SALES PRICE:
            </fo:block>
          </fo:table-cell>
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="right" end-indent="4pt" xsl:use-attribute-sets="headerFont" line-height="0.6cm" >
              $<xsl:value-of select="@HAprvdInAgreementTotal"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="right" end-indent="4pt" xsl:use-attribute-sets="headerFont" line-height="0.6cm" color="#CC0000">
              $<xsl:value-of select="@HDifferenceTotal"/>
<!--              $<xsl:value-of select="@HAprvdAdjustmentTotal"/> -->
            </fo:block>
          </fo:table-cell>
          <fo:table-cell  border-style = "solid" border-width = "0.1mm">
            <fo:block text-align="right" end-indent="4pt" xsl:use-attribute-sets="headerFontLarge" line-height="0.6cm">
              $<xsl:value-of select="@HAprvdTotal"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>
  
  <xsl:template match="CATEGORY[SUBCATEGORY]" mode="sum">
    <fo:table-row height="0.7cm">         
      <fo:table-cell  border-style = "solid" border-width = "0.1mm">
        <fo:block text-align="left" xsl:use-attribute-sets="subHeaderFont" line-height="0.6cm" >
          <xsl:variable name="sectName" select="@CAT_DESC"/>
          <xsl:choose>
            <xsl:when test = "$sectName = 'General Information'">
              <xsl:text>BASE PRICE</xsl:text>
            </xsl:when>
            <xsl:otherwise>              
              <xsl:value-of select="@CAT_DESC"/>
            </xsl:otherwise>
          </xsl:choose>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell  border-style = "solid" border-width = "0.1mm">
        <fo:block text-align="right"  end-indent="4pt" xsl:use-attribute-sets="subHeaderFont" >
          $<xsl:value-of select="@CRelAprvdInAgreementTotal + @CRelAprvdAdjustmentTotal"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell  border-style = "solid" border-width = "0.1mm">
        <fo:block text-align="right"  end-indent="4pt" xsl:use-attribute-sets="subHeaderFont" color="#CC0000" >
          $<xsl:value-of select="@CAprvdAdjustmentTotal + @CAprvdInAgreementTotal - @CRelAprvdInAgreementTotal - @CRelAprvdAdjustmentTotal"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell  border-style = "solid" border-width = "0.1mm">
        <fo:block text-align="right" end-indent="4pt" xsl:use-attribute-sets="subHeaderFont" line-height="0.6cm">
          $<xsl:value-of select="@CAprvdTotal"/>
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c) 2004-2007. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="" htmlbaseurl="" outputurl="" processortype="saxon8" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator="" ><advancedProp name="sInitialMode" value=""/><advancedProp name="bXsltOneIsOkay" value="true"/><advancedProp name="bSchemaAware" value="true"/><advancedProp name="bXml11" value="false"/><advancedProp name="iValidation" value="0"/><advancedProp name="bExtensions" value="true"/><advancedProp name="iWhitespace" value="0"/><advancedProp name="sInitialTemplate" value=""/><advancedProp name="bTinyTree" value="true"/><advancedProp name="bWarnings" value="true"/><advancedProp name="bUseDTD" value="false"/><advancedProp name="iErrorHandling" value="fatal"/></scenario></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->