Help with XSLT

Im writing a stylesheet which output our information to a third party and I need to make a change.

Im editing the following script (below) to return upto four row, how do I handle counting hte number of rows in this case


[code]
        <table name="mortgagearrears">
          <xsl:if test="../cblmlon0/arr-missed/item[@index = 1]/@data != 0">
            <row count="1" indexID="">
              <column name="lastUpdated"/>
              <column name="avcID">{AVCID}</column>
              <column name="payments">
                <xsl:value-of select="format-number(../cblmlon0/arr-missed/item[@index = 1]/@data,'0')"/>
              </column>
              <column name="months">12</column>
              <column name="total"/>
              <!-- JHC MOD <column name="date_issued"/> -->
              <column name="date_satisfied"/>
              <!-- JHC MOD <column name="monthly_payment"/> -->
              <column name="monthsSatisfied"/>
            </row>
          </xsl:if>
          <xsl:if test="sum(../cblmlon0/arr-missed/item[@index > 1]/@data) != 0">
            <row indexID="">
              <xsl:attribute name="count">
                <xsl:if test="../cblmlon0/arr-missed/item[@index = 1]/@data = 0">1</xsl:if>
                <xsl:if test="../cblmlon0/arr-missed/item[@index = 1]/@data != 0">2</xsl:if>
              </xsl:attribute>
              <column name="lastUpdated"/>
              <column name="avcID">{AVCID}</column>
              <column name="payments">
                <xsl:value-of select="sum(../cblmlon0/arr-missed/item[@index > 1]/@data)"/>
              </column>
              <column name="months">36</column>
              <column name="total"/>
              <!-- JHC MOD <column name="date_issued"/> -->
              <column name="date_satisfied"/>
              <!-- JHC MOD <column name="monthly_payment"/> -->
              <column name="monthsSatisfied"/>
            </row>
          </xsl:if>
[/code]
LVL 5
paranoidcookieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PeterCiuffettiCommented:
You may need to post the whole XSLT and an example source document.  The question isn't really that clear.  Normally, counting is done with one of the following:

The steps of an xsl:for-each loop can output the row count this way:
<xsl:value-of select="position()"/>

Or if you want to get the total number of elements in some context, you can use:
<xsl:value-of select="count(some-element)"/>

And a variant of this would count all the previous siblings and so, with a little increment, can give you the counter you need for the present element:
<xsl:value-of select="count(preceding-sibling:* + 1)"/>
0
paranoidcookieAuthor Commented:
The xslt is below I cannto post the source document as im using another probgram to pull information out of our systems on the fly.
Im not very good at explainations im afraid basically we record the number of missed mortgage payments in order to source loans.
We record how many missed payments in 0-3 months
how many missed payments in 3-6 months
how many missed payments in 6-12 months
how many missed payments in 12-24

In the past the third party wanted culmulative figures for last 12 and last 36 months they have no agreed to record the sme as us. Trouble is I didnt set up the XML and really dont knowhow to deal with it.
We need to send a each period 0-3 3-6 etc in a numbered row with some other details. But if only one payment was missed 11 months ago there would only be one row.

We dont currently use a for-each loop to read in would that be a better solution?

[code]

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  10/11/04 Many updates to the schema to fix various errors / update CCS codes
  08/11/04 jhc ccs wish all fields to follow 0 no 1 yes 2 not sure format so replaced yesno-num and
           yesno-char for the boolean equivalents
  04/11/04 jhc key fact and prefered contact mods
  27/10/04 mjd mod whole bunch of changes
  26/10/04 mjd mod go through every numeric value and only display if not zero
  26/10/04 mjd mod finish off jhc mods
-->
<xsl:stylesheet extension-element-prefixes="date" version="1.0" xmlns:date="http://exslt.org/dates-and-times" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" method="xml" standalone="yes" version="1.0"/>
  <xsl:key match="/advances/application/cblcons0/company/item[@data != '']" name="cons-lookup" use="@index"/>
  <xsl:variable name="acct-ref">
    <xsl:value-of select="/advances/application/loan/@acct-ref"/>
  </xsl:variable>
  <xsl:variable name="loan-type">
    <xsl:value-of select="/advances/application/loan/@type"/>
  </xsl:variable>
  <!-- functions to convert from advances codings to ccs -->
  <!-- JHC MOD Changed from 1 and to 0 1 boolean type -->
  <!--takes a boolean and returns a boolean number-->
  <xsl:template name="boolean-num">
    <xsl:param name="indicator"/>
    <xsl:if test="not($indicator)">0</xsl:if>
    <xsl:if test="$indicator">1</xsl:if>
  </xsl:template>
  <!--takes a Y/N character and returns a boolean number-->
  <xsl:template name="boolean-char">
    <xsl:param name="indicator"/>
    <xsl:if test="$indicator = 'N'">0</xsl:if>
    <xsl:if test="$indicator = 'Y'">1</xsl:if>
  </xsl:template>
  <!-- JHC mod removed yesno-char and yesno-num -->
  <xsl:template name="gender">
    <xsl:param name="sex"/>
    <xsl:choose>
      <xsl:when test="$sex='M'">1</xsl:when>
      <xsl:when test="$sex='F'">2</xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:template>
  <!-- End JHC Mod -->
  <!-- Deposit -->
  <xsl:template name="deposit">
    <!-- Complicated by the fact we store a value and ccs expect a yes no
       Therefore in the case of a remortgage its always blank
       For FTB and BTL if a value present answer is yes otherwise answer is no -->
    <xsl:param name="deposit-amt"/>
    <!-- Value of deposit -->
    <xsl:param name="type"/>
    <!-- Type of purchase -->
    <xsl:choose>
      <!-- first test if either purcahse or buy to let -->
      <xsl:when test="$type = 'R'">
        <xsl:choose>
          <!-- next test if value > 0 if so thn deposit true otherwise no deposit -->
          <xsl:when test="deposit-amt > 0">1</xsl:when>
          <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- If not purchase or buy to let return nothing -->
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:template>
  <!-- Contrstruction Type -->
  <xsl:template name="construction">
    <!-- JHC Types
      1 standard
      2 Thatched
      3 Timber Framed
      4 Concrete -->
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type='010'">1</xsl:when>
      <xsl:when test="$type='015'">1</xsl:when>
      <xsl:when test="$type='BRK'">1</xsl:when>
      <xsl:when test="$type='020'">1</xsl:when>
      <xsl:when test="$type='025'">1</xsl:when>
      <xsl:when test="$type='030'">0</xsl:when>
      <xsl:when test="$type='035'">0</xsl:when>
      <xsl:when test="$type='040'">0</xsl:when>
      <xsl:when test="$type='045'">0</xsl:when>
      <xsl:when test="$type='050'">0</xsl:when>
      <xsl:when test="$type='055'">0</xsl:when>
      <xsl:when test="$type='060'">0</xsl:when>
      <xsl:when test="$type='065'">0</xsl:when>
      <xsl:when test="$type='CON'">4</xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:template>
  <!-- JHC MOD added preferred contact lookup -->
  <xsl:template name="PrefContact">
    <xsl:param name="pref"/>
    <xsl:param name="home"/>
    <xsl:param name="work"/>
    <xsl:param name="mobile"/>
    <xsl:param name="email"/>
    <xsl:choose>
      <xsl:when test="$pref = $home">2</xsl:when>
      <xsl:when test="$pref = $mobile">4</xsl:when>
      <xsl:when test="$pref = $work">3</xsl:when>
      <xsl:when test="$pref = $email">1</xsl:when>
    </xsl:choose>
  </xsl:template>
  <!--property type-->
  <xsl:template name="property-type">
    <xsl:param name="type"/>
    <xsl:choose>
      <!-- TODO this types don't match exactly so there is a bit of guesswork-->
      <xsl:when test="$type = 'B'">2</xsl:when>
      <xsl:when test="$type = 'F'">3</xsl:when>
      <xsl:when test="$type = 'M'">4</xsl:when>
      <xsl:when test="$type = 'T'">1</xsl:when>
      <xsl:when test="$type = 'S'">1</xsl:when>
      <xsl:when test="$type = 'D'">1</xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="house-type">
    <xsl:param name="type"/>
    <xsl:choose>
      <!-- TODO this types don't match exactly so there is a bit of guesswork-->
      <xsl:when test="$type = 'B'">1</xsl:when>
      <xsl:when test="$type = 'F'">3</xsl:when>
      <xsl:when test="$type = 'M'">3</xsl:when>
      <xsl:when test="$type = 'T'">2</xsl:when>
      <xsl:when test="$type = 'S'">5</xsl:when>
      <xsl:when test="$type = 'D'">1</xsl:when>
    </xsl:choose>
  </xsl:template>
  <!--wall type-->
  <xsl:template name="wall-type">
    <!--  types are:
                  1 ? Brick
                  2 ? Stone
                  3 ? Concrete
                  4 ? Timber
                  5 ? Granite
                  6 ? Sandstone
                  7 - Other
            -->
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type = '010' or $type = '015' or $type = 'BRK' ">1</xsl:when>
      <xsl:when test="$type = '020' or $type = '025' ">2</xsl:when>
      <xsl:when test="$type = '030' or $type = '045' or $type= 'CON' ">3</xsl:when>
      <xsl:when test="$type = '040' or $type = '045' or $type = '060' or $type = '065' ">4</xsl:when>
      <!-- <xsl:when test="$type =  ">5</xsl:when>
                  <xsl:when test="$type =  ">6</xsl:when>
                  <xsl:when test="$type =  ">7</xsl:when> -->
    </xsl:choose>
  </xsl:template>
  <!--roof type-->
  <xsl:template name="roof-type">
    <!--  types are:
                  1 ? Slate
                  2 ? Tile
                  3 ? Ashphalt
                  4 ? Concrete
                  5 ? Timber
                  6 ? Metal
                  7 ? Thatch
                  8 - Other
            -->
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type = '015' or $type = '025' or $type = '045' ">1</xsl:when>
      <xsl:when test="$type = '010' or $type = '020' or $type = '040' ">2</xsl:when>
      <!-- <xsl:when test="$type =  ">3</xsl:when>
                  <xsl:when test="$type =  ">4</xsl:when>
                  <xsl:when test="$type =  ">5</xsl:when>
                  <xsl:when test="$type =  ">6</xsl:when> -->
      <xsl:when test="$type = '050' or $type = '055' or $type = '060' or $type = '065' ">7</xsl:when>
    </xsl:choose>
  </xsl:template>
  <!--applicant title-->
  <xsl:template name="title">
    <!--  titles are... to many to enumerate... -->
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type = 'Mr' ">1</xsl:when>
      <xsl:when test="$type = 'Mrs' ">2</xsl:when>
      <xsl:when test="$type = 'Miss' ">3</xsl:when>
      <xsl:when test="$type = 'Ms' ">4</xsl:when>
      <xsl:when test="$type = 'Dr' ">5</xsl:when>
      <xsl:when test="$type = 'Rev' ">6</xsl:when>
      <xsl:when test="$type = 'Prof' ">7</xsl:when>
      <xsl:when test="$type = 'Sir' ">8</xsl:when>
      <xsl:when test="$type = 'Captain' ">9</xsl:when>
      <xsl:when test="$type = 'Lady' ">10</xsl:when>
      <xsl:when test="$type = 'Major' ">11</xsl:when>
      <xsl:when test="$type = 'Lord' ">12</xsl:when>
      <xsl:when test="$type = 'Colonel' ">13</xsl:when>
      <xsl:when test="$type = 'Viscount' ">14</xsl:when>
      <xsl:when test="$type = 'Brigadier' ">15</xsl:when>
      <xsl:when test="$type = 'Lieut Col' ">16</xsl:when>
      <xsl:when test="$type = 'The Right Honourable' ">17</xsl:when>
      <xsl:when test="$type = 'Madame' ">18</xsl:when>
      <xsl:when test="$type = 'Canon' ">19</xsl:when>
      <xsl:when test="$type = 'Deacon' ">20</xsl:when>
      <xsl:when test="$type = 'Deaconess' ">21</xsl:when>
      <xsl:when test="$type = 'Father' ">22</xsl:when>
      <xsl:when test="$type = 'Sister' ">23</xsl:when>
      <xsl:when test="$type = 'Reverend' ">24</xsl:when>
      <xsl:when test="$type = 'The Right Reverend' ">25</xsl:when>
      <xsl:when test="$type = 'The Venerable' ">26</xsl:when>
      <xsl:when test="$type = 'Honourable' ">27</xsl:when>
      <xsl:when test="$type = 'Honourable Mrs' ">28</xsl:when>
      <xsl:when test="$type = 'Judge' ">29</xsl:when>
      <xsl:when test="$type = 'Admiral' ">30</xsl:when>
      <xsl:when test="$type = 'Air Commodore' ">31</xsl:when>
      <xsl:when test="$type = 'Air Vice-Marshall' ">32</xsl:when>
      <xsl:when test="$type = 'Commander' ">33</xsl:when>
      <xsl:when test="$type = 'Commodore' ">34</xsl:when>
      <xsl:when test="$type = 'Corporal' ">35</xsl:when>
      <xsl:when test="$type = 'Flight Lieutenant' ">36</xsl:when>
      <xsl:when test="$type = 'Flight Sergeant' ">37</xsl:when>
      <xsl:when test="$type = 'Guardsman' ">38</xsl:when>
      <xsl:when test="$type = 'Group Captain' ">39</xsl:when>
      <xsl:when test="$type = 'Lance Corporal' ">40</xsl:when>
      <xsl:when test="$type = 'Lieutenant' ">41</xsl:when>
      <xsl:when test="$type = 'Lieutenant Cmmdr' ">42</xsl:when>
      <xsl:when test="$type = 'Major General' ">43</xsl:when>
      <xsl:when test="$type = 'Rear Admiral' ">44</xsl:when>
      <xsl:when test="$type = 'Private' ">45</xsl:when>
      <xsl:when test="$type = 'Sergeant' ">46</xsl:when>
      <xsl:when test="$type = 'Squadron Leader' ">47</xsl:when>
      <xsl:when test="$type = 'Staff Sergeant' ">48</xsl:when>
      <xsl:when test="$type = 'Trooper' ">49</xsl:when>
      <xsl:when test="$type = 'Warrant Officer' ">50</xsl:when>
      <xsl:when test="$type = 'Warrant Officer 1st' ">51</xsl:when>
      <xsl:when test="$type = 'Wing Commander' ">52</xsl:when>
      <xsl:when test="$type = 'Baron' ">53</xsl:when>
      <xsl:when test="$type = 'Baroness' ">54</xsl:when>
      <xsl:when test="$type = 'Earl' ">55</xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="loan-purpose">
    <!--  titles are:
            1 First Time Buyer
            2 Home Mover (STB)
            3 Rmg - Capital Raising
            4 Rmg - No Capital Raising
            5 Rmg - Home Improvements
            6 Rmg - Debt Consolidation
            7 Rmg - Buy other Property
            8 Rmg - Business Purposes
            9 Buy to Let
            10 Let to Buy
            11 Buy to Let Remortgage
       -->
    <xsl:param name="purpose"/>
    <xsl:choose>
      <!--JHC MOD Using Chris Guants Codes -->
      <xsl:when test="$purpose = 'RTB'">1</xsl:when>
      <xsl:when test="$purpose = 'TU1'">1</xsl:when>
      <xsl:when test="$purpose = 'PS1'">2</xsl:when>
      <xsl:when test="$purpose = 'CA1'">3</xsl:when>
      <xsl:when test="$purpose = 'CN1'">3</xsl:when>
      <xsl:when test="$purpose = 'COM'">3</xsl:when>
      <xsl:when test="$purpose = 'EQR'">3</xsl:when>
      <xsl:when test="$purpose = 'FEE'">3</xsl:when>
      <xsl:when test="$purpose = 'HO1'">3</xsl:when>
      <xsl:when test="$purpose = 'LAN'">3</xsl:when>
      <xsl:when test="$purpose = 'MED'">3</xsl:when>
      <xsl:when test="$purpose = 'NTM'">3</xsl:when>
      <xsl:when test="$purpose = 'PAR'">3</xsl:when>
      <xsl:when test="$purpose = 'TAX'">3</xsl:when>
      <xsl:when test="$purpose = 'VEH'">3</xsl:when>
      <xsl:when test="$purpose = 'XMA'">3</xsl:when>
      <xsl:when test="$purpose = 'SHO'">3</xsl:when>
      <xsl:when test="$purpose = 'HOM'">3</xsl:when>
      <xsl:when test="$purpose = 'CHP'">4</xsl:when>
      <xsl:when test="$purpose = 'BTL'">5</xsl:when>
      <xsl:when test="$purpose = 'CON'">6</xsl:when>
      <xsl:when test="$purpose = 'FTB'">6</xsl:when>
      <xsl:when test="$purpose = 'TIM'">7</xsl:when>
      <xsl:when test="$purpose = 'PPA'">7</xsl:when>
      <xsl:when test="$purpose = 'PUK'">7</xsl:when>
      <xsl:when test="$purpose = 'HH'">7</xsl:when>
      <xsl:when test="$purpose = 'BEV'">8</xsl:when>
      <xsl:when test="$purpose = 'BL1'">8</xsl:when>
      <xsl:when test="$purpose = 'OV1'">9</xsl:when>
      <xsl:when test="$purpose = 'WD1'">11</xsl:when>
      <xsl:otherwise>3</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="marital-status">
    <!--  thingies are:
            1 Single
            2 Engaged
            3 Married
            4 Divorced
            5 Widow(er)
            6 Separated
      -->
    <xsl:param name="status"/>
    <xsl:choose>
      <xsl:when test="$status = 'S' ">1</xsl:when>
      <!-- <xsl:when test="$status = '' ">2</xsl:when> -->
      <xsl:when test="$status = 'M' ">3</xsl:when>
      <xsl:when test="$status = 'D' ">4</xsl:when>
      <xsl:when test="$status = 'W' ">5</xsl:when>
      <xsl:when test="$status = 'P' ">6</xsl:when>
      <xsl:when test="$status = 'L' ">7</xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="adverse-credit-type">
    <!--
            1 CCJs
            2 Defaults
            3 Mortgage Arrears
            4 Current IVA
            5 Bankrupt
            6 Repossesion
            7 Previous IVA
      -->
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type = 'X' ">1</xsl:when>
      <xsl:when test="$type = 'X' ">2</xsl:when>
      <xsl:when test="$type = 'X' ">3</xsl:when>
      <xsl:when test="$type = 'X' ">4</xsl:when>
      <xsl:when test="$type = 'X' ">5</xsl:when>
      <xsl:when test="$type = 'X' ">6</xsl:when>
      <xsl:when test="$type = 'X' ">7</xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="employment-status">
    <!--
            1 Employed
            2 Self-Employed
            3 Contractor
            4 Controlling Director
            5 Not Employed
      -->
    <xsl:param name="status"/>
    <xsl:param name="director"/>
    <xsl:choose>
      <xsl:when test="$director = 'Y' ">4</xsl:when>
      <xsl:when test="$status = 'E' ">1</xsl:when>
      <xsl:when test="$status = 'S' ">2</xsl:when>
      <xsl:when test="$status = 'U' or $status = 'H'">5</xsl:when>
      <xsl:when test="$status = 'R' ">6</xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="employment-type">
    <!--
            1 Director
            2 Professional
            3 Skilled
            4 Non-Skilled
      -->
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type = 'X' ">1</xsl:when>
      <xsl:when test="$type = 'X' ">2</xsl:when>
      <xsl:when test="$type = 'X' ">3</xsl:when>
      <xsl:when test="$type = 'X' ">4</xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="income-source">
    <!--
            1 Car Allowance
            2 Investment Income
            3 Large Town Allowance
            4 Shift Allowance
            5 Maintenance Payments
            6 Mortgage Allowance
            7 Non-Contributory Pension
            8 Rental Income
            9 Other
      -->
    <xsl:param name="source"/>
    <xsl:choose>
      <xsl:when test="$source = ''"/>
      <xsl:when test="$source = 'X' ">1</xsl:when>
      <xsl:when test="$source = 'IVT' ">2</xsl:when>
      <xsl:when test="$source = 'X' ">3</xsl:when>
      <xsl:when test="$source = 'X' ">4</xsl:when>
      <xsl:when test="$source = 'CSA' ">5</xsl:when>
      <xsl:when test="$source = 'X' ">6</xsl:when>
      <xsl:when test="$source = 'PEN' ">7</xsl:when>
      <xsl:when test="$source = 'REN' ">8</xsl:when>
      <xsl:otherwise>9</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="cons-purpose">
    <!--
      CC Credit Card
      LO Loan
      HP Hire Purchase
      MO Mortgage
      RT Retail Credit
      SC Secured Loan
      DF Default
-->
    <xsl:param name="purpose"/>
    <xsl:choose>
      <xsl:when test="$purpose = 'CC'">Credit Card</xsl:when>
      <xsl:when test="$purpose = 'LO'">Loan</xsl:when>
      <xsl:when test="$purpose = 'HP'">Hire Purchase</xsl:when>
      <xsl:when test="$purpose = 'MO'">Mortgage</xsl:when>
      <xsl:when test="$purpose = 'RT'">Retail Credit</xsl:when>
      <xsl:when test="$purpose = 'SC'">Secured Loan</xsl:when>
      <xsl:when test="$purpose = 'DF'">Default</xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="cons-type">
    <!--
      CC Credit Card
      LO Loan
      HP Hire Purchase
      MO Mortgage
      RT Retail Credit
      SC Secured Loan
      DF Default
-->
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type = 'CC'">4</xsl:when>
      <xsl:when test="$type = 'LO'">1</xsl:when>
      <xsl:when test="$type = 'HP'">2</xsl:when>
      <xsl:when test="$type = 'MO'">8</xsl:when>
      <xsl:when test="$type = 'RT'">9</xsl:when>
      <xsl:when test="$type = 'SC'">9</xsl:when>
      <xsl:when test="$type = 'DF'">9</xsl:when>
      <xsl:otherwise>9</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="location">
    <xsl:param name="region"/>
    <xsl:choose>
      <xsl:when test="$region = 'SC'">SM</xsl:when>
      <xsl:when test="$region = 'W'">WA</xsl:when>
      <xsl:when test="$region = 'NI'">NI</xsl:when>
      <xsl:otherwise>EM</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--employment nature-->
  <xsl:template name="employment-nature">
    <xsl:param name="part-full"/>
    <xsl:param name="perm-temp"/>
    <xsl:choose>
      <xsl:when test="$part-full = 'F' and $perm-temp = 'P'">1</xsl:when>
      <xsl:when test="$part-full = 'P' and $perm-temp = 'P'">2</xsl:when>
      <xsl:when test="$part-full = 'F' and $perm-temp = 'T'">3</xsl:when>
      <xsl:when test="$part-full = 'P' and $perm-temp = 'T'">4</xsl:when>
    </xsl:choose>
  </xsl:template>
  <!--repayment method-->
  <xsl:template name="repayment-method">
    <xsl:param name="method"/>
    <xsl:if test="$method = 'R'">1</xsl:if>
    <xsl:if test="$method = 'I'">2</xsl:if>
  </xsl:template>
  <!--date add-->
  <xsl:template name="date-add">
    <xsl:param name="date" select="date:date()"/>
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:value-of select="date:add($date, concat('-P', $year, 'Y', $month, 'M'))"/>
  </xsl:template>
  <!-- Interest Style -->
  <xsl:template name="interest-style">
    <xsl:param name="interest"/>
    <xsl:choose>
      <xsl:when test="$interest = 'S'">1</xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:template>
  <!--occupant type-->
  <xsl:template name="occupant-type">
    <xsl:param name="type"/>
    <xsl:param name="tenant"/>
    <xsl:if test="$type = 'H'">1</xsl:if>
    <xsl:if test="$type = 'T' and $tenant = 'L'">3</xsl:if>
    <xsl:if test="$type = 'T'">2</xsl:if>
  </xsl:template>
  <xsl:template  name="penalty-duration">
   <!-- Lenght of ERP Penalty -->
     <xsl:param name="type"/>
     <xsl:param name="duration"/>
     <xsl:choose>
        <xsl:when test="$type = 'M'">
          <xsl:if test="$duration != 0">
            <xsl:value-of select="$duration"/>
          </xsl:if>
        </xsl:when>
        <xsl:otherwise/>
     </xsl:choose>
  </xsl:template>
  <!-- did try and do this as a literal result element but this doesn't work if you want template functions-->
  <xsl:template match="/">
    <xsl:comment>advances export to ccs</xsl:comment>
    <ccs>
      <ccsHeader>
        <advancesUserId>
          <xsl:value-of select="advances/application/cblmlon0/underwriter/@data"/>
        </advancesUserId>
      </ccsHeader>
      <database name="demo">
        <xsl:apply-templates select="advances/application"/>
      </database>
    </ccs>
  </xsl:template>
  <!--do the actual content here-->
  <xsl:template match="advances/application">
    <caseSpecific>
      <table name="cases">
        <row indexID="">
          <column name="userID"/>
          <column name="uniqueID">
            <xsl:value-of select="$acct-ref"/>
          </column>
          <column name="locked"/>
          <column name="salesProcess">tel</column>
          <column name="dateCreated">
            <xsl:value-of select="cblappl0/date-rec/@data"/>
          </column>
          <column name="lastUpdated"/>
          <column name="lastAccessed"/>
          <column name="status">
            <xsl:text>live</xsl:text>
          </column>
          <column name="breach"/>
          <column name="underReview"/>
          <column name="parentID"/>
          <column name="archived"/>
          <column name="forcedPass"/>
          <column name="product_applied"/>
          <column name="uploaded">1</column>
        </row>
      </table>
      <table name="keyinfo">
        <!-- JHC Mod CCS change due to ccs incompetance and indecision by freedom-->
        <row indexID="">
          <column name="lastUpdated"/>
          <column name="caseID">
            <xsl:text>{CASEID}</xsl:text>
          </column>
          <column name="payoff">
            <!-- JHC Mod -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/payoff-house/@data"/>
            </xsl:call-template>
          </column>
          <column name="move">
            <!--JHC Mod -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/move-house/@data"/>
            </xsl:call-template>
          </column>
          <column name="income_change">
            <!-- JHC Mod changed to boolean-char from noyesnot-->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/income-change/@data"/>
            </xsl:call-template>
          </column>
          <column name="expend_change">
            <!-- JHC Mod changed to boolean-char from noyesnot-->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/expend-change/@data"/>
            </xsl:call-template>
          </column>
          <column name="redempt_charge">
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/no-erp/@data"/>
            </xsl:call-template>
          </column>
          <column name="high_lend_charge">
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/nohigh-loanfee/@data"/>
            </xsl:call-template>
          </column>
          <column name="speed">
            <!-- JHC Mod changed from TODO to COMPLETE-SPEED -->
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/complete-speed/@data"/>
            </xsl:call-template>
          </column>
          <column name="lend_policy">
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/add-fees-costs/@data"/>
            </xsl:call-template>
          </column>
          <column name="vary_repayment">
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/pref-flexible/@data"/>
            </xsl:call-template>
          </column>
          <column name="payment_static">
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/prefer-fixed/@data"/>
            </xsl:call-template>
          </column>
          <column name="payment_reduce">
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/prefer-capped/@data"/>
            </xsl:call-template>
          </column>
          <column name="payment_cheapest">
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/pref-discount/@data"/>
            </xsl:call-template>
          </column>
          <column name="payment_interest">
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/prefer-TODO/@data"/>
            </xsl:call-template>
          </column>
          <column name="financial_benefit_months"/>
          <column name="financial_benefit_years">
            <xsl:choose>
              <xsl:when test="cblfact0/prefer-fixed/@data = 'Y'">
                <xsl:if test="cblfact0/fixed-years/@data != 0">
                  <xsl:value-of select="cblfact0/fixed-years/@data"/>
                </xsl:if>
              </xsl:when>
              <xsl:when test="cblfact0/prefer-capped/@data = 'Y'">
                <xsl:if test="cblfact0/capped-years/@data != 0">
                  <xsl:value-of select="cblfact0/capped-years/@data"/>
                </xsl:if>
              </xsl:when>
              <xsl:when test="cblfact0/pref-discount/@data = 'Y'">
                <xsl:if test="cblfact0/disc-years/@data != 0">
                  <xsl:value-of select="cblfact0/disc-years/@data"/>
                </xsl:if>
              </xsl:when>
            </xsl:choose>
          </column>
          <column name="cat_standard">
            <!-- JHC Mod Changed to be blank -->
          </column>
          <column name="portable">
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/portable/@data"/>
            </xsl:call-template>
          </column>
          <column name="cash_sum">
            <!-- JHC Mod added cash sum handler -->
            <!-- JHC Mod changed from noyesnot-num -->
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblfact0/pref-cashback/@data"/>
            </xsl:call-template>
          </column>
        </row>
      </table>
      <table name="insurancevaluables">
        <row indexID="">
          <column name="icID"/>
          <column name="valuabletype"/>
          <column name="description"/>
          <column name="value"/>
          <column name="lastUpdated"/>
        </row>
      </table>
      <table name="mainDetail">
        <!-- get the details from slon0, ulon0 or mlon0 -->
        <xsl:choose>
          <xsl:when test="$loan-type = 'S'">
            <row indexID="">
              <column name="lastUpdated"/>
              <column name="caseID">
                <xsl:text>{CASEID}</xsl:text>
              </column>
              <column name="ref">
                <xsl:value-of select="$acct-ref"/>
              </column>
              <column name="repaymentMethod">
                <xsl:call-template name="repayment-method">
                  <xsl:with-param name="method" select="cblfact0/prf-pay-method/@data"/>
                </xsl:call-template>
              </column>
              <column name="price"/>
              <column name="deposit"/>
              <column name="loan">
                <xsl:value-of select="cblslon0/loan-value/@data"/>
              </column>
              <column name="ltv"/>
              <column name="term">
                <xsl:value-of select="cblslon0/period/@data"/>
              </column>
              <column name="purpose">
                <!-- JHC Mod added Purpose codes -->
                <xsl:call-template name="loan-purpose">
                  <xsl:with-param name="purpose" select="cblmlon0/purpose-1/@data"/>
                </xsl:call-template>
              </column>
              <column name="repaymentAmount"/>
              <column name="repaymentTerm"/>
              <column name="interestOnlyAmount"/>
              <column name="interestOnlyTerm"/>
              <column name="capital_raise"/>
              <column name="debt_consol"/>
              <column name="broker_fee">
                <xsl:value-of select="cblslon0/broker-fee/@data"/>
              </column>
              <column name="legal_fee">
                <xsl:value-of select="cblslon0/legal-fee/@data"/>
              </column>
              <column name="stamp_duty"/>
              <column name="other"/>
              <column name="contingency"/>
              <column name="total_borrow"/>
              <column name="applicant_no"/>
              <column name="main_applicant"/>
              <column name="selfCert"/>
            </row>
          </xsl:when>
          <xsl:when test="$loan-type = 'U'">
            <row indexID="">
              <column name="lastUpdated"/>
              <column name="caseID">
                <xsl:text>{CASEID}</xsl:text>
              </column>
              <column name="ref">
                <xsl:value-of select="$acct-ref"/>
              </column>
              <column name="repaymentMethod"/>
              <column name="price"/>
              <column name="deposit"/>
              <column name="loan">
                <xsl:value-of select="cblulon0/loan-value/@data"/>
              </column>
              <column name="ltv"/>
              <column name="term">
                <xsl:value-of select="cblulon0/period/@data"/>
              </column>
              <column name="purpose"/>
              <column name="repaymentAmount"/>
              <column name="`Term"/>
              <column name="interestAmount"/>
              <column name="interestOnlyTerm"/>
              <column name="capital_raise"/>
              <column name="debt_consol"/>
              <column name="broker_fee">
                <xsl:value-of select="cblulon0/broker-fee/@data"/>
              </column>
              <column name="legal_fee">
                <xsl:value-of select="cblulon0/legal-fee/@data"/>
              </column>
              <column name="stamp_duty"/>
              <column name="other"/>
              <column name="contingency"/>
              <column name="total_borrow"/>
              <column name="applicant_no"/>
              <column name="main_applicant"/>
              <column name="selfCert"/>
            </row>
          </xsl:when>
          <xsl:when test="$loan-type = 'M'">
            <row indexID="">
              <column name="lastUpdated"/>
              <column name="caseID">
                <xsl:text>{CASEID}</xsl:text>
              </column>
              <column name="ref">
                <xsl:value-of select="$acct-ref"/>
              </column>
              <column name="repaymentMethod">
                <xsl:call-template name="repayment-method">
                  <xsl:with-param name="method" select="cblfact0/prf-pay-method/@data"/>
                </xsl:call-template>
              </column>
              <column name="price">
                <xsl:if test="cblprop0/est-val/@data != 0">
                  <xsl:value-of select="cblprop0/est-val/@data"/>
                </xsl:if>
              </column>
              <column name="deposit">
                <xsl:if test="fact0/deposit-avail/@data != 0">
                  <xsl:value-of select="fact0/deposit-avail/@data"/>
                </xsl:if>
              </column>
              <column name="loan">
                <xsl:if test="cblmlon0/loan-value/@data != 0">
                  <xsl:value-of select="cblmlon0/loan-value/@data"/>
                </xsl:if>
              </column>
              <column name="ltv">
                <xsl:if test="cblprop0/ltv-used/@data != 0">
                  <xsl:value-of select="cblprop0/ltv-used/@data"/>
                </xsl:if>
              </column>
              <column name="term">
                <!-- jhc <xsl:value-of select="cblmlon0/period/@data"/> -->
                <xsl:if test="cblmlon0/period/@data != 0">
                  <xsl:value-of select="cblmlon0/period/@data"/>
                </xsl:if>
              </column>
              <column name="purpose">
                <xsl:call-template name="loan-purpose">
                  <xsl:with-param name="purpose" select="cblmlon0/purpose-1/@data"/>
                </xsl:call-template>
              </column>
              <column name="repaymentAmount"/>
              <column name="repaymentTerm"/>
              <column name="interestOnlyAmount"/>
              <column name="interestOnlyTerm"/>
              <column name="capital_raise"/>
              <column name="debt_consol">
                <xsl:if test="sum(cblcons0/settle-amt/item/@data) != 0">
                  <xsl:value-of select="sum(cblcons0/settle-amt/item/@data)"/>
                </xsl:if>
              </column>
              <column name="broker_fee">
                <xsl:if test="cblmlon0/broker-fee/@data != 0">
                  <xsl:value-of select="cblmlon0/broker-fee/@data"/>
                </xsl:if>
              </column>
              <column name="legal_fee">
                <xsl:if test="cblmlon0/legal-fee/@data != 0">
                  <xsl:value-of select="cblmlon0/legal-fee/@data"/>
                </xsl:if>
              </column>
              <column name="stamp_duty"/>
              <column name="other"/>
              <column name="contingency"/>
              <column name="total_borrow"/>
              <column name="applicant_no">
                <xsl:value-of select="applicant[position() = last()]/@number"/>
              </column>
              <column name="main_applicant">1</column>
              <column name="selfCert"/>
            </row>
          </xsl:when>
        </xsl:choose>
      </table>
      <table name="newmortgage">
        <row indexID="">
          <column name="lastUpdated"/>
          <column name="caseID">
            <xsl:text>{CASEID}</xsl:text>
          </column>
          <column name="right_to_buy">
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblprop0/council-house/@data"/>
            </xsl:call-template>
          </column>
          <column name="rtbvalue">
            <xsl:if test="cblprop0/council-val/@data != 0">
              <xsl:value-of select="cblprop0/council-val/@data"/>
            </xsl:if>
          </column>
          <column name="over_price"/>
          <column name="opvalue"/>
          <column name="opdetail"/>
          <column name="only_property">
            <xsl:call-template name="boolean-char">
               <xsl:with-param name="indicator" select="cblfact0/only-mortgage/@data"/>
            </xsl:call-template>
          </column>
          <column name="shared_owner">
            <xsl:call-template name="boolean-num">
              <xsl:with-param name="indicator" select="cblappl0/homeown-tenant/@data = 'S'"/>
            </xsl:call-template>
          </column>
          <column name="sopercent">
            <xsl:if test="cblprop0/percnt-own/@data != 0">
              <xsl:value-of select="cblprop0/percnt-own/@data"/>
            </xsl:if>
          </column>
          <column name="sobody"/>
          <column name="home_improvements">
            <!-- If Mortgage purpose is Homeimprovments set to yes otherwise unknown -->
            <xsl:if test="cblmlon0/purpose-1/@data = 'BTL'">1</xsl:if>
          </column>
          <column name="hidetails"/>
          <column name="hicost"/>
          <column name="deposit">
            <xsl:call-template name="deposit">
              <xsl:with-param name="deposit-amt" select="cblfact0/deposit-avail/@data"/>
              <xsl:with-param name="type" select="cblfact0/purch-remort/@data"/>
            </xsl:call-template>
          </column>
          <column name="deposit_amount">
            <xsl:if test="cblfact0/deposit-avail/@data !=0">
              <xsl:value-of select="cblfact0/deposit-avail/@data"/>
            </xsl:if>
          </column>
          <column name="deposit_source">
            <xsl:value-of select="cblfact0/deposit-type/description/@data"/>
          </column>
          <column name="notes">
            <xsl:value-of select="cblmlon0/purpose-1/description/@data"/>
            <xsl:if test="cblmlon0/purpose-2/description/@data != ''">
              <xsl:value-of select="' '"/>
              <xsl:value-of select="cblmlon0/purpose-2/description/@data"/>
            </xsl:if>
          </column>
        </row>
      </table>
      <table name="property">
        <row indexID="">
          <column name="lastUpdated"/>
          <column name="caseID">
            <xsl:text>{CASEID}</xsl:text>
          </column>
          <column name="address"/>
          <column name="location">
            <xsl:call-template name="location">
              <xsl:with-param name="region" select="cblcusts/appl-postcode/region/@data"/>
            </xsl:call-template>
          </column>
          <column name="postcode">
            <xsl:value-of select="cblcusts/appl-postcode/@data"/>
          </column>
          <column name="type">
            <xsl:call-template name="property-type">
              <xsl:with-param name="type" select="cblprop0/property-type/@data"/>
            </xsl:call-template>
          </column>
          <column name="beds">
            <xsl:if test="cblcusts/num-bedrooms/@data != 0">
              <xsl:value-of select="cblcusts/num-bedrooms/@data"/>
            </xsl:if>
          </column>
          <column name="bathrooms">
            <xsl:if test="cblcusts/num-bathrooms/@data != 0">
              <xsl:value-of select="cblcusts/num-bathrooms/@data"/>
            </xsl:if>
          </column>
          <column name="wcs"/>
          <column name="tenure"/>
          <column name="lease"/>
          <column name="floors">
            <xsl:if test="cblprop0/number-floors/@data != 0">
              <xsl:value-of select="cblprop0/number-floors/@data"/>
            </xsl:if>
          </column>
          <column name="your_floor">
            <xsl:if test="cblprop0/on-floor/@data != 0">
              <xsl:value-of select="cblprop0/on-floor/@data"/>
            </xsl:if>
          </column>
          <column name="ground_rent"/>
          <column name="year_built">
            <xsl:if test="cblcusts/year-built/@data != 0">
              <xsl:value-of select="cblcusts/year-built/@data"/>
            </xsl:if>
          </column>
          <column name="service_charge"/>
          <column name="lounge">
            <xsl:if test="cblcusts/num-rec-rooms/@data != 0">
              <xsl:value-of select="cblcusts/num-rec-rooms/@data"/>
            </xsl:if>
          </column>
          <column name="dining"/>
          <column name="kitchen"/>
          <column name="additional_rooms"/>
          <column name="commercial"/>
          <column name="garage">
            <xsl:if test="cblprop0/garage/@data = 'N'">0</xsl:if>
            <xsl:if test="cblprop0/garage/@data = 'Y'">1</xsl:if>
          </column>
          <column name="over_commercial"/>
          <column name="approved_locks"/>
          <column name="alarmed"/>
          <column name="neighbourhood"/>
          <column name="listed"/>
          <column name="excavation"/>
          <column name="extended"/>
          <column name="carparking_onsite"/>
          <column name="carparking_offsite"/>
          <column name="ela">
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblprop0/formly-council/@data"/>
            </xsl:call-template>
          </column>
          <column name="shared_ownership">
            <xsl:call-template name="boolean-num">
              <xsl:with-param name="indicator" select="cblappl0/homeown-tenant/@data = 'S'"/>
            </xsl:call-template>
          </column>
          <column name="back_to_back"/>
          <column name="self_build"/>
          <column name="flying_freehold"/>
          <column name="shared_equity"/>
          <column name="agricultural"/>
          <column name="semi_commercial">
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblprop0/semi-commerce/@data"/>
            </xsl:call-template>
          </column>
          <column name="studio_flat"/>
          <column name="lift_in_block"/>
          <column name="no_nhbc"/>
          <column name="timber_frame"/>
          <column name="all_timber"/>
          <column name="concrete"/>
          <column name="underpinned"/>
          <column name="thatched_roof"/>
          <column name="steel_frame"/>
          <column name="notes"/>
          <column name="buildingNo">
            <xsl:value-of select="cblcusts/appl-house-num/@data"/>
          </column>
          <column name="address_1">
            <xsl:value-of select="cblcusts/appl-addr1/@data"/>
          </column>
          <column name="address_2">
            <xsl:value-of select="cblcusts/appl-addr2/@data"/>
          </column>
          <column name="town">
            <xsl:value-of select="cblcusts/appl-addr3/@data"/>
          </column>
          <column name="county">
            <xsl:value-of select="cblcusts/appl-addr4/@data"/>
          </column>
          <column name="termAtMortgageEnd"/>
          <column name="occupancyType"/>
          <column name="houseType">
            <xsl:call-template name="house-type">
              <xsl:with-param name="type" select="cblprop0/property-type/@data"/>
            </xsl:call-template>
          </column>
          <column name="roof">
            <xsl:call-template name="roof-type">
              <xsl:with-param name="type" select="cblprop0/cnst-type/@data"/>
            </xsl:call-template>
          </column>
          <column name="walls">
            <xsl:call-template name="wall-type">
              <xsl:with-param name="type" select="cblprop0/cnst-type/@data"/>
            </xsl:call-template>
          </column>
          <column name="standardConstruction">
            <!-- JHC Added a new template for construction type -->
            <xsl:call-template name="construction">
              <xsl:with-param name="type" select="cblprop0/cnst-type/@data"/>
            </xsl:call-template>
          </column>
        </row>
      </table>
      <table name="notes">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="notes"/>
          <!-- JHC MOD -->
          <column name="caseID">{CASEID}</column>
          <column name="date_entered"/>
          <!-- End JHC MOD -->
        </row>
      </table>
      <table name="products">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="caseID">
              <xsl:text>{CASEID}</xsl:text>
          </column>
          <column name="amount">
            <xsl:value-of select="cblmlon0/loan-value/@data"/>
          </column>
          <column name="term">
            <xsl:value-of select="cblmlon0/period/@data div 12"/>
          </column>
          <column name="repaymentMethod">
            <xsl:call-template name="repayment-method">
              <xsl:with-param name="method" select="cblfact0/prf-pay-method/@data"/>
            </xsl:call-template>
          </column>
          <column name="repaymentAmount"/>
          <column name="repaymentTerm"/>
          <column name="interestOnlyAmount"/>
          <column name="interestOnlyTerm"/>
          <column name="prodID"/>
        </row>
      </table>
    </caseSpecific>
    <xsl:apply-templates select="applicant"/>
  </xsl:template>
  <!-- individual applicants -->
  <xsl:template match="applicant">
    <xsl:variable name="app-num" select="@number"/>
    <applicantSpecific appNumber="{$app-num}">
      <table name="applicants">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="caseID">
            <xsl:text>{CASEID}</xsl:text>
          </column>
          <column name="title">
            <xsl:call-template name="title">
              <xsl:with-param name="type" select="cblcust0/appl-title/@data"/>
            </xsl:call-template>
          </column>
          <column name="firstName">
            <xsl:value-of select="cblcust0/appl-1st-name/@data"/>
          </column>
          <column name="secondName">
            <xsl:value-of select="cblcust0/appl-surname/@data"/>
          </column>
          <column name="previous">
            <xsl:value-of select="cblcust0/appl-prev-name/@data"/>
          </column>
          <column name="buyerType"/>
          <column name="employmentStatus">
            <xsl:call-template name="employment-status">
              <xsl:with-param name="status" select="cblempl0[@acct-empl-num = 1]/empl-self/@data"/>
              <xsl:with-param name="director" select="cblempl0[@acct-empl-num = 1]/director/@data"/>
            </xsl:call-template>
          </column>
          <!-- Edited by JHC -->
          <column name="sex">
            <xsl:call-template name="gender">
              <xsl:with-param name="sex" select="cblcust0/sex/@data"/>
            </xsl:call-template>
          </column>
          <!-- End JHC Edit -->
          <column name="nationality">
            <xsl:value-of select="cblcust0/nationality/@data"/>
          </column>
          <column name="dob">
            <xsl:value-of select="/advances/application/cblstat0/d-o-b/item[@index = $app-num]/@data"/>
          </column>
          <column name="age">
            <xsl:value-of select="/advances/application/cblstat0/age/item[@index = $app-num]/@data"/>
          </column>
          <column name="ageAtMortgageEnd"/>
          <column name="monthsContinuousEmp">
            <xsl:if test="sum(cblempl0[@acct-empl-num &lt; ../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']/@acct-empl-num or count(../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']) = 0]/years/@data) + sum(cblempl0[@acct-empl-num &lt; ../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']/@acct-empl-num or count(../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']) = 0]/months/@data) != 0">
              <xsl:value-of select="12 * sum(cblempl0[@acct-empl-num &lt; ../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']/@acct-empl-num or count(../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']) = 0]/years/@data) + sum(cblempl0[@acct-empl-num &lt; ../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']/@acct-empl-num or count(../cblempl0[empl-self/@data != 'E' and empl-self/@data != 'S']) = 0]/months/@data)"/>
            </xsl:if>
          </column>
          <column name="noDependants">
            <xsl:value-of select="cblcust0/num-dependants/@data"/>
          </column>
          <column name="noDependants18">
            <xsl:value-of select="cblcust0/num-dependant1/@data"/>
          </column>
          <column name="maritialStatus">
            <xsl:call-template name="marital-status">
              <xsl:with-param name="status" select="cblcust0/marital-status/@data"/>
            </xsl:call-template>
          </column>
          <column name="ninumber">
            <xsl:value-of select="cblcust0/ni-number/@data"/>
          </column>
          <column name="expatriate">
            <xsl:if test="cblcust0/nationality/@data != 114">
              <xsl:call-template name="boolean-num">
                <xsl:with-param name="indicator" select="cblcust0/uk-resident/@data = 'Y'"/>
              </xsl:call-template>
            </xsl:if>
          </column>
          <column name="foreign_citizen">
            <xsl:call-template name="boolean-num">
              <xsl:with-param name="indicator" select="cblcust0/nationality/@data != 114"/>
            </xsl:call-template>
          </column>
          <column name="retirementDate"/>
          <column name="hasCCJs">
            <xsl:call-template name="boolean-num">
              <xsl:with-param name="indicator" select="cblarrs0/ccj-amount/item/@data != 0"/>
            </xsl:call-template>
          </column>
          <column name="hasDefaults">
            <xsl:call-template name="boolean-num">
              <xsl:with-param name="indicator" select="cblarrs0/def-costs/item/@data != 0"/>
            </xsl:call-template>
          </column>
          <xsl:if test="$app-num = 1">
            <column name="hasArrears">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblmlon0/arrears/@data"/>
              </xsl:call-template>
            </column>
            <column name="hasBankrupt">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblfact0/ever-bankrupt/@data"/>
              </xsl:call-template>
            </column>
            <column name="hasIVA">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblfact0/iva-proceeding/@data"/>
              </xsl:call-template>
            </column>
            <column name="hasRepossesion">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblfact0/prop-repossed/@data"/>
              </xsl:call-template>
            </column>
            <column name="hasPreviousIVA"/>
            <column name="isPrimary">1</column>
          </xsl:if>
          <xsl:if test="$app-num > 1">
            <column name="hasArrears"/>
            <column name="hasBankrupt"/>
            <column name="hasIVA"/>
            <column name="hasRepossesion"/>
            <column name="hasPreviousIVA"/>
            <column name="isPrimary">0</column>
          </xsl:if>
        </row>
      </table>
      <table name="moneyLaunder2">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="numberNames"/>
          <column name="numberAddress"/>
          <column name="applicantID">{APPLICANTID}</column>
        </row>
      </table>
      <table name="addressEvidence">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="mLID">{MLID}</column>
          <column name="addressType"/>
          <column name="addressRef"/>
          <column name="addressDate"/>
          <column name="addressCopy"/>
          <column name="addressDetail"/>
          <column name="addressCurrent"/>
          <column name="number"/>
          <column name="filename"/>
        </row>
      </table>
      <!-- previous addresses-->
      <table name="addressHistory">
        <xsl:for-each select="cblprev0">
          <row indexID="">
            <xsl:attribute name="count">
              <xsl:value-of select="position()"/>
            </xsl:attribute>
            <column name="lastUpdated"/>
            <column name="address"/>
            <column name="buildingNo">
              <xsl:value-of select="appl-house-num/@data"/>
            </column>
            <column name="address_1">
              <xsl:value-of select="appl-addr1/@data"/>
            </column>
            <column name="address_2">
              <xsl:value-of select="appl-addr2/@data"/>
            </column>
            <column name="town">
              <xsl:value-of select="appl-addr3/@data"/>
            </column>
            <column name="county">
              <xsl:value-of select="appl-addr4/@data"/>
            </column>
            <column name="postcode">
              <xsl:value-of select="appl-postcode/@data"/>
            </column>
            <column name="startdate"/>
            <column name="enddate"/>
            <column name="yearsAtAddress">
              <xsl:if test="years/@data != 0">
                <xsl:value-of select="years/@data"/>
              </xsl:if>
            </column>
            <column name="monthsAtAddress">
              <xsl:if test="months/@data != 0">
                <xsl:value-of select="months/@data"/>
              </xsl:if>
            </column>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
        </xsl:for-each>
      </table>
      <table name="affordability">
        <row count="1" indexID="">
          <column name="utils"/>
          <column name="food"/>
          <column name="holiday"/>
          <column name="travel"/>
          <column name="insurance"/>
          <column name="other"/>
          <column name="total_out"/>
          <column name="hasOutgoings">
            <xsl:call-template name="boolean-num">
              <!-- JHC MOD Changed indicatior-->
              <xsl:with-param name="indicator" select="count(../cblcons0/client-no/item[key('cons-lookup',@index) and (@data = $app-num or  ($app-num = 1 and @data = ''))]) != 0"/>
            </xsl:call-template>
          </column>
          <column name="applicantID">{APPLICANTID}</column>
        </row>
      </table>
      <!--the next lot of tables are all blank-->
      <table name="existingTenancy">
        <row count="1" indexID="">
          <column name="monthlyRent"/>
          <column name="landlordRef"/>
          <column name="telephoneSTD"/>
          <column name="telephone"/>
          <column name="faxSTD"/>
          <column name="fax"/>
          <column name="startdate"/>
          <column name="enddate"/>
          <column name="buildingNo"/>
          <column name="address_1"/>
          <column name="address_2"/>
          <column name="town"/>
          <column name="county"/>
          <column name="postcode"/>
          <column name="lastUpdated"/>
          <column name="applicantID">{APPLICANTID}</column>
        </row>
      </table>
      <table name="health">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="height"/>
          <column name="weight"/>
          <column name="doctor"/>
          <column name="address"/>
          <column name="postcode"/>
          <column name="cigarette"/>
          <column name="alcohol"/>
          <column name="medical_cond"/>
          <column name="buildingNo"/>
          <column name="address_1"/>
          <column name="address_2"/>
          <column name="town"/>
          <column name="county"/>
          <column name="applicantID">{APPLICANTID}</column>
        </row>
      </table>
      <table name="namesEvidence">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="mLID">{MLID}</column>
          <column name="nameType"/>
          <column name="nameRef"/>
          <column name="nameDate"/>
          <column name="nameCopy"/>
          <column name="nameDetail"/>
          <column name="number"/>
          <column name="filename"/>
        </row>
      </table>
      <!--stuff that only applies to main applicant-->
      <xsl:if test="$app-num = 1">
        <!--total our different types of adverse credit-->
        <!-- JHC Mod changed to one table -->
        <table name="adversecredit">
          <!--CCJs-->
          <row count="1" indexID="">
            <column name="lastUpdated"/>
            <column name="type">1</column>
            <column name="no">
              <xsl:value-of select="count(cblarrs0/ccj-amount/item[@data > 0])"/>
            </column>
            <column name="value">
              <xsl:if test="sum(cblarrs0/ccj-amount/item/@data) != 0">
                <xsl:value-of select="sum(cblarrs0/ccj-amount/item/@data)"/>
              </xsl:if>
            </column>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
          <!--Defaults-->
          <row count="2" indexID="">
            <column name="lastUpdated"/>
            <column name="type">2</column>
            <column name="no">
              <xsl:value-of select="count(cblarrs0/def-costs/item[@data > 0])"/>
            </column>
            <column name="value">
              <xsl:value-of select="sum(cblarrs0/def-costs/item/@data)"/>
            </column>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
          <!--Mortgage Arrears-->
          <row count="3" indexID="">
            <column name="lastUpdated"/>
            <column name="type">3</column>
            <column name="no">
              <xsl:value-of select="sum(../cblmlon0/arr-missed/item/@data)"/>
            </column>
            <column name="value"/>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
          <!--Bankrupt-->
          <row count="4" indexID="">
            <column name="lastUpdated"/>
            <column name="type">4</column>
            <column name="no">
              <xsl:value-of select="count(../cblfact0/ever-bankrupt[@data = 'Y'])"/>
            </column>
            <column name="value"/>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
          <!--Current IVA-->
          <row count="5" indexID="">
            <column name="lastUpdated"/>
            <column name="type">5</column>
            <column name="no">
              <xsl:value-of select="count(../cblfact0/iva-proceeding[@data = 'Y'])"/>
            </column>
            <column name="value"/>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
          <!--Repossesion-->
          <row count="6" indexID="">
            <column name="lastUpdated"/>
            <column name="type">6</column>
            <column name="no">
              <xsl:value-of select="count(../cblfact0/prop-repossed[@data = 'Y'])"/>
            </column>
            <column name="value"/>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
        </table>
        <!-- End JHC MOD -->
        <!--TODO Previous IVA-->
        <table name="credithistory">
          <row count="1" indexID="">
            <column name="lastUpdated"/>
            <column name="loan_refusal">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblfact0/loan-refused/@data"/>
              </xsl:call-template>
            </column>
            <column name="refusal_detail">
              <xsl:value-of select="../cblfact0/date-refused/@data"/>
            </column>
            <column name="ccj">
              <xsl:call-template name="boolean-num">
                <xsl:with-param name="indicator" select="cblarrs0/ccj-amount/item/@data != 0"/>
              </xsl:call-template>
            </column>
            <column name="bankrupt">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblfact0/ever-bankrupt/@data"/>
              </xsl:call-template>
            </column>
            <column name="arrears">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblmlon0/arrears/@data"/>
              </xsl:call-template>
            </column>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
        </table>
        <table name="existingMortgage">
          <row count="1" indexID="">
            <column name="lastUpdated"/>
            <column name="type"/>
            <column name="term_remain">
              <xsl:value-of select="../cblprop0/term-outstand/@data"/>
            </column>
            <column name="term"/>
            <column name="provider">
              <xsl:value-of select="../cblprop0/n1st-mort-code/@data"/>
            </column>
            <column name="account_no">
              <xsl:value-of select="../cblprop0/roll-num/@data"/>
            </column>
            <column name="interest_type">
              <!-- We dont actually store this -->
            </column>
            <column name="interest_style">
              <xsl:call-template name="interest-style">
                <xsl:with-param name="interest" select="../cblprop0/mortg-type/@data"/>
              </xsl:call-template>
            </column>
            <column name="penalties">
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="../cblmlon0/early-redempt/@data"/>
              </xsl:call-template>
            </column>
            <column name="penalty_amount">
              <xsl:if test="../cblfact0/erp-type/@data = 'A' or ../cblfact0/erp-type/@data = 'M'">
                <xsl:value-of select="../cblmlon0/redempt-amt/@data"/>
              </xsl:if>
            </column>
            <column name="penalty_redemption"/>
            <column name="penalty_period">
              <xsl:call-template name="penalty-duration">
            <xsl:with-param name="type" select="../cblfact0/erp-type/@data"/>
            <xsl:with-param name="duration" select="../cblfact0/erp-num/@data"/>
            </xsl:call-template>
            </column>
            <column name="accept_penalties">
              <!-- JHC MOD -->
              <xsl:call-template name="boolean-num">
                <xsl:with-param name="indicator" select="cblfact0/no-erp/@data ='N'"/>
              </xsl:call-template>
            </column>
            <column name="portable_mortgage">
              <!-- JHC MOD -->
              <xsl:call-template name="boolean-char">
                <xsl:with-param name="indicator" select="cblfact0/portable/@data"/>
              </xsl:call-template>
            </column>
            <column name="loan">
              <xsl:if test="../cblprop0/n1st-orig-mort/@data != 0">
                <xsl:value-of select="../cblprop0/n1st-orig-mort/@data"/>
              </xsl:if>
            </column>
            <column name="balance">
              <xsl:if test="../cblprop0/n1st-mort-bal/@data != 0">
                <xsl:value-of select="../cblprop0/n1st-mort-bal/@data"/>
              </xsl:if>
            </column>
            <column name="month_payment">
              <xsl:if test="../cblincm0/n1st-mort-pay/@data != 0">
                <xsl:value-of select="../cblincm0/n1st-mort-pay/@data"/>
              </xsl:if>
            </column>
            <column name="sale_price">
              <xsl:if test="../cblprop0/selling-price/@data != 0">
                <xsl:value-of select="../cblprop0/selling-price/@data"/>
              </xsl:if>
            </column>
            <column name="interest_rate">
              <xsl:if test="../cblprop0/curr-intr-rate/@data != 0">
                <xsl:value-of select="../cblprop0/curr-intr-rate/@data"/>
              </xsl:if>
            </column>
            <column name="sell_house">
              <xsl:call-template name="boolean-num">
                <xsl:with-param name="indicator" select="../cblprop0/selling-price/@data != 0"/>
              </xsl:call-template>
            </column>
            <column name="interest_period_ends"/>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
        </table>
        <table name="iva">
          <row count="1" indexID="">
            <column name="lastUpdated"/>
            <column name="avcID">{AVCID}</column>
            <column name="payments_met">
            <!-- JHC Mod added lookup for IVA payments met -->
            <xsl:call-template name="boolean-char">
                   <xsl:with-param name="indicator" select="../cblfact0/iva-payments/@data"/>
             </xsl:call-template>
          </column>
          </row>
        </table>
        <table name="mortgagearrears">
          <xsl:if test="../cblmlon0/arr-missed/item[@index = 1]/@data != 0">
            <row count="1" indexID="">
              <column name="lastUpdated"/>
              <column name="avcID">{AVCID}</column>
              <column name="payments">
                <xsl:value-of select="format-number(../cblmlon0/arr-missed/item[@index = 1]/@data,'0')"/>
              </column>
              <column name="months">12</column>
              <column name="total"/>
              <!-- JHC MOD <column name="date_issued"/> -->
              <column name="date_satisfied"/>
              <!-- JHC MOD <column name="monthly_payment"/> -->
              <column name="monthsSatisfied"/>
            </row>
          </xsl:if>
          <xsl:if test="sum(../cblmlon0/arr-missed/item[@index > 1]/@data) != 0">
            <row indexID="">
              <xsl:attribute name="count">
                <xsl:if test="../cblmlon0/arr-missed/item[@index = 1]/@data = 0">1</xsl:if>
                <xsl:if test="../cblmlon0/arr-missed/item[@index = 1]/@data != 0">2</xsl:if>
              </xsl:attribute>
              <column name="lastUpdated"/>
              <column name="avcID">{AVCID}</column>
              <column name="payments">
                <xsl:value-of select="sum(../cblmlon0/arr-missed/item[@index > 1]/@data)"/>
              </column>
              <column name="months">36</column>
              <column name="total"/>
              <!-- JHC MOD <column name="date_issued"/> -->
              <column name="date_satisfied"/>
              <!-- JHC MOD <column name="monthly_payment"/> -->
              <column name="monthsSatisfied"/>
            </row>
          </xsl:if>
        </table>
        <table name="previousiva">
          <row count="1" indexID="">
            <column name="lastUpdated"/>
            <column name="avcID">{AVCID}</column>
            <column name="months_met"/>
          </row>
        </table>
        <table name="repossesion">
          <row count="1" indexID="">
            <column name="lastUpdated"/>
            <column name="avcID">{AVCID}</column>
            <column name="months"/>
          </row>
        </table>
      </xsl:if>
      <!--back to tables for all applicants-->
      <table name="bankrupt">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="avcID">{AVCID}</column>
          <column name="months"/>
        </row>
      </table>
      <!--loop through cblarrs0 to get ccj records-->
      <table name="ccj">
        <xsl:for-each select="cblarrs0/ccj-amount/item[@data != 0]">
          <row count="{position()}" indexID="">
            <xsl:apply-templates mode="arrs-ccj" select="../..">
              <xsl:with-param name="index" select="@index"/>
            </xsl:apply-templates>
          </row>
        </xsl:for-each>
      </table>
      <!--loop through cblarrs0 to get defaults records-->
      <table name="defaults">
        <xsl:for-each select="cblarrs0/def-costs/item[@data != 0]">
          <row count="{position()}" indexID="">
            <xsl:apply-templates mode="arrs-def" select="../..">
              <xsl:with-param name="index" select="@index"/>
            </xsl:apply-templates>
          </row>
        </xsl:for-each>
      </table>
      <table name="contactinfo">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="address"/>
          <column name="postcode">
            <xsl:value-of select="cblcust0/appl-postcode/@data"/>
          </column>
          <column name="workTelSTD">
            <xsl:value-of select="cblphone/bus/STD/@data"/>
          </column>
          <column name="workTel">
            <xsl:value-of select="cblphone/bus/number/@data"/>
          </column>
          <column name="ext">
            <xsl:value-of select="cblphone/bus-ext/@data"/>
          </column>
          <column name="homeTelSTD">
            <xsl:value-of select="cblphone/home/STD/@data"/>
          </column>
          <column name="homeTel">
            <xsl:value-of select="cblphone/home/number/@data"/>
          </column>
          <column name="mobileTel">
            <xsl:value-of select="cblphone/mobile/@data"/>
          </column>
          <column name="faxSTD"/>
          <column name="fax"/>
          <column name="email">
            <xsl:value-of select="cblcust0/appl-email-1/@data"/>
          </column>
          <column name="preferContact">
            <xsl:call-template name="PrefContact">
              <xsl:with-param name="pref" select="cblphone/pref/@data"/>
              <xsl:with-param name="home" select="cblphone/home/@data"/>
              <xsl:with-param name="work" select="cblphone/bus/@data"/>
              <xsl:with-param name="mobile" select="cblphone/mobile/@data"/>
            </xsl:call-template>
            <!-- JHC Mod Altered Prefered Contact lookup
            <xsl:value-of select="cblphone/pref/@data"/>
             -->
          </column>
          <column name="datemovedin">
            <xsl:call-template name="date-add">
              <xsl:with-param name="year" select="cblcust0/appl-years/@data"/>
              <xsl:with-param name="month" select="cblcust0/appl-months/@data"/>
            </xsl:call-template>
          </column>
          <column name="yearsAtAddress">
            <xsl:if test="cblcust0/appl-years/@data != 0">
              <xsl:value-of select="cblcust0/appl-years/@data"/>
            </xsl:if>
          </column>
          <column name="monthsAtAddress">
            <xsl:if test="cblcust0/appl-months/@data != 0">
              <xsl:value-of select="cblcust0/appl-months/@data"/>
            </xsl:if>
          </column>
          <column name="occupantType">
            <xsl:if test="$app-num = 1">
              <xsl:call-template name="occupant-type">
                <xsl:with-param name="type" select="../cblappl0/homeown-tenant/@data"/>
                <xsl:with-param name="tenant" select="../cblappl0/tenant-type/@data"/>
              </xsl:call-template>
            </xsl:if>
            <xsl:if test="$app-num = 2">
              <xsl:call-template name="occupant-type">
                <xsl:with-param name="type" select="../cblappl0/homeown-tenan2/@data"/>
                <xsl:with-param name="tenant" select="../cblappl0/tenant-type2/@data"/>
              </xsl:call-template>
            </xsl:if>
          </column>
          <column name="electoralroll">
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblcust0/elect-roll/@data"/>
            </xsl:call-template>
          </column>
          <column name="buildingNo">
            <xsl:value-of select="cblcust0/appl-house-num/@data"/>
          </column>
          <column name="address_1">
            <xsl:value-of select="cblcust0/appl-addr1/@data"/>
          </column>
          <column name="address_2">
            <xsl:value-of select="cblcust0/appl-addr2/@data"/>
          </column>
          <column name="town">
            <xsl:value-of select="cblcust0/appl-addr3/@data"/>
          </column>
          <column name="county">
            <xsl:value-of select="cblcust0/appl-addr4/@data"/>
          </column>
          <column name="applicantID">{APPLICANTID}</column>
        </row>
      </table>
      <!-- all employment records for applicant -->
      <table name="employment">
        <xsl:for-each select="cblempl0">
          <row indexID="">
            <xsl:attribute name="count">
              <xsl:value-of select="position()"/>
            </xsl:attribute>
            <column name="lastUpdated"/>
            <column name="entrytype">
              <xsl:if test="number(@acct-empl-num) = 1">1</xsl:if>
              <xsl:if test="number(@acct-empl-num) != 1">2</xsl:if>
            </column>
            <column name="emptype"/>
            <column name="nature">
              <xsl:call-template name="employment-nature">
                <xsl:with-param name="part-full" select="part-full-time/@data"/>
                <xsl:with-param name="perm-temp" select="perm-temp/@data"/>
              </xsl:call-template>
            </column>
            <column name="cmppercent">
              <xsl:if test="pcnt-shares/@data != 0">
                <xsl:value-of select="pcnt-shares/@data"/>
              </xsl:if>
            </column>
            <column name="startdate">
              <xsl:call-template name="date-add">
                <xsl:with-param name="year" select="sum(../cblempl0[@acct-empl-num &lt;= current()/@acct-empl-num]/years/@data)"/>
                <xsl:with-param name="month" select="sum(../cblempl0[@acct-empl-num &lt;= current()/@acct-empl-num]/months/@data)"/>
              </xsl:call-template>
            </column>
            <column name="enddate">
              <xsl:if test="@acct-empl-num > 1">
                <xsl:call-template name="date-add">
                  <xsl:with-param name="year" select="sum(../cblempl0[@acct-empl-num &lt; current()/@acct-empl-num]/years/@data)"/>
                  <xsl:with-param name="month" select="sum(../cblempl0[@acct-empl-num &lt; current()/@acct-empl-num]/months/@data)"/>
                </xsl:call-template>
              </xsl:if>
            </column>
            <column name="probation"/>
            <column name="probation_date"/>
            <column name="occupation">
              <xsl:text>26</xsl:text>
            </column>
            <column name="employer">
              <xsl:value-of select="company/@data"/>
            </column>
            <column name="address"/>
            <column name="buildingNo">
              <xsl:value-of select="house-num/@data"/>
            </column>
            <column name="address_1">
              <xsl:value-of select="addr1/@data"/>
            </column>
            <column name="address_2">
              <xsl:value-of select="addr2/@data"/>
            </column>
            <column name="town">
              <xsl:value-of select="addr3/@data"/>
            </column>
            <column name="county">
              <xsl:value-of select="addr4/@data"/>
            </column>
            <column name="postcode">
              <xsl:value-of select="postcode/@data"/>
            </column>
            <column name="telephoneSTD">
              <xsl:value-of select="phone/STD/@data"/>
            </column>
            <column name="telephone">
              <xsl:value-of select="phone/number/@data"/>
            </column>
            <column name="faxSTD"/>
            <column name="fax"/>
            <column name="expectedend"/>
            <column name="occupation_other">
              <xsl:value-of select="desc/@data"/>
            </column>
            <column name="applicantID">{APPLICANTID}</column>
          </row>
        </xsl:for-each>
      </table>
      <table name="income">
        <row count="1" indexID="">
          <column name="lastUpdated"/>
          <column name="priBasic">
            <xsl:if test="../cblincm0/inc-appl/item[@index = $app-num]/@data != 0">
              <xsl:value-of select="../cblincm0/inc-appl/item[@index = $app-num]/@data"/>
            </xsl:if>
          </column>
          <column name="priGuranteedOvertime"/>
          <column name="priRegularBonus"/>
          <column name="seBasic"/>
          <column name="seGuranteedOvertime"/>
          <column name="seRegularBonus"/>
          <column name="otherEarnings">
            <xsl:choose>
              <xsl:when test="$app-num = 1">
                <xsl:call-template name="boolean-num">
                  <xsl:with-param name="indicator" select="sum(../cblincm0/othr-val-1/item/@data) > 0"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="$app-num = 2">
                <xsl:call-template name="boolean-num">
                  <xsl:with-param name="indicator" select="sum(../cblincm0/othr-val-2/item/@data) > 0"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="$app-num = 3">
                <xsl:call-template name="boolean-num">
                  <xsl:with-param name="indicator" select="sum(../cblincm0/othr-val-3/item/@data) > 0"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="$app-num = 4">
                <xsl:call-template name="boolean-num">
                  <xsl:with-param name="indicator" select="sum(../cblincm0/othr-val-4/item/@data) > 0"/>
                </xsl:call-template>
              </xsl:when>
            </xsl:choose>
          </column>
          <!-- do a choose on app-num cos the applicant is part of the field name not in the array. yuck -->
          <xsl:choose>
            <xsl:when test="$app-num = 1">
              <column name="other1">
                <xsl:if test="../cblincm0/othr-val-1/item[@index = 1]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-1/item[@index = 1]/@data"/>
                </xsl:if>
              </column>
              <column name="source1">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-1/item[@index = 1]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other2">
                <xsl:if test="../cblincm0/othr-val-1/item[@index = 2]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-1/item[@index = 2]/@data"/>
                </xsl:if>
              </column>
              <column name="source2">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-1/item[@index = 2]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other3">
                <xsl:if test="../cblincm0/othr-val-1/item[@index = 3]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-1/item[@index = 3]/@data"/>
                </xsl:if>
              </column>
              <column name="source3">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-1/item[@index = 3]/@data"/>
                </xsl:call-template>
              </column>
            </xsl:when>
            <xsl:when test="$app-num = 2">
              <column name="other1">
                <xsl:if test="../cblincm0/othr-val-2/item[@index = 1]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-2/item[@index = 1]/@data"/>
                </xsl:if>
              </column>
              <column name="source1">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-2/item[@index = 1]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other2">
                <xsl:if test="../cblincm0/othr-val-2/item[@index = 2]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-2/item[@index = 2]/@data"/>
                </xsl:if>
              </column>
              <column name="source2">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-2/item[@index = 2]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other3">
                <xsl:if test="../cblincm0/othr-val-2/item[@index = 3]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-2/item[@index = 3]/@data"/>
                </xsl:if>
              </column>
              <column name="source3">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-2/item[@index = 3]/@data"/>
                </xsl:call-template>
              </column>
            </xsl:when>
            <xsl:when test="$app-num = 3">
              <column name="other1">
                <xsl:if test="../cblincm0/othr-val-3/item[@index = 1]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-3/item[@index = 1]/@data"/>
                </xsl:if>
              </column>
              <column name="source1">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-3/item[@index = 1]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other2">
                <xsl:if test="../cblincm0/othr-val-3/item[@index = 2]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-3/item[@index = 2]/@data"/>
                </xsl:if>
              </column>
              <column name="source2">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-2/item[@index = 2]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other3">
                <xsl:if test="../cblincm0/othr-val-3/item[@index = 3]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-3/item[@index = 3]/@data"/>
                </xsl:if>
              </column>
              <column name="source3">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-3/item[@index = 3]/@data"/>
                </xsl:call-template>
              </column>
            </xsl:when>
            <xsl:when test="$app-num = 4">
              <column name="other1">
                <xsl:if test="../cblincm0/othr-val-4/item[@index = 1]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-4/item[@index = 1]/@data"/>
                </xsl:if>
              </column>
              <column name="source1">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-4/item[@index = 1]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other2">
                <xsl:if test="../cblincm0/othr-val-4/item[@index = 2]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-4/item[@index = 2]/@data"/>
                </xsl:if>
              </column>
              <column name="source2">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-4/item[@index = 2]/@data"/>
                </xsl:call-template>
              </column>
              <column name="other3">
                <xsl:if test="../cblincm0/othr-val-4/item[@index = 3]/@data != 0">
                  <xsl:value-of select="../cblincm0/othr-val-4/item[@index = 3]/@data"/>
                </xsl:if>
              </column>
              <column name="source3">
                <xsl:call-template name="income-source">
                  <xsl:with-param name="source" select="../cblincm0/othr-desc-4/item[@index = 3]/@data"/>
                </xsl:call-template>
              </column>
            </xsl:when>
          </xsl:choose>
          <column name="selfGross"/>
          <column name="monthEst"/>
          <column name="yearEst"/>
          <column name="noMonthsEst"/>
          <column name="noYearsEst"/>
          <column name="last3NetProfit1">
              <xsl:value-of select="../cblempl0/n3yrs-profits/@data"/>

                         <!-- Having a real battle geting this field to work
            <xsl:if test="cblempl0/n3yrs-profits/@data != 0">
              <xsl:value-of select="cblempl0/n3yrs-profits/@data"/>
            </xsl:if> -->
          </column>
          <column name="endYear1"/>
          <column name="last3NetProfit2"/>
          <column name="endYear2"/>
          <column name="last3NetProfit3"/>
          <column name="endYear3"/>
          <column name="last3NetProfit4"/>
          <column name="nextYearEarnings"/>
          <column name="accountsAvailable">
            <xsl:call-template name="boolean-char">
              <xsl:with-param name="indicator" select="cblsacc0/acc-proof/@data"/>
            </xsl:call-template>
          </column>
          <column name="accountantRef"/>
          <column name="accountantFirm">
            <xsl:value-of select="cblsacc0/acct-name/@data"/>
          </column>
          <column name="buildingNo"/>
          <column name="address_1">
            <xsl:value-of select="cblsacc0/acct-addr1/@data"/>
          </column>
          <column name="address_2">
            <xsl:value-of select="cblsacc0/acct-addr2/@data"/>
          </column>
          <column name="town">
            <xsl:value-of select="cblsacc0/acct-addr3/@data"/>
          </column>
          <column name="county">
            <xsl:value-of select="cblsacc0/acct-addr4/@data"/>
          </column>
          <column name="postcode">
            <xsl:value-of select="cblsacc0/acct-postcode/@data"/>
          </column>
          <column name="telephoneSTD">
            <xsl:value-of select="cblsacc0/acct-tel/STD/@data"/>
          </column>
          <column name="telephone">
            <xsl:value-of select="cblsacc0/acct-tel/number/@data"/>
          </column>
          <column name="faxSTD">
            <xsl:value-of select="cblsacc0/acct-fax/STD/@data"/>
          </column>
          <column name="fax">
            <xsl:value-of select="cblsacc0/acct-fax/number/@data"/>
          </column>
          <column name="incomeDeclining"/>
          <column name="applicantID">{APPLICANTID}</column>
        </row>
      </table>
      <!--consolidation. gonna be tricky...-->
      <table name="outgoings">
        <xsl:for-each select="../cblcons0/client-no/item[key('cons-lookup',@index) and (@data = $app-num or  ($app-num = 1 and @data = ''))]">
          <!--have to use $cons-num cos trying to path to @index is impossible (i think)-->
          <xsl:variable name="cons-num" select="./@index"/>
          <row count="{position()}" indexID="">
            <xsl:apply-templates select="../..">
              <xsl:with-param name="index" select="$cons-num"/>
            </xsl:apply-templates>
          </row>
        </xsl:for-each>
      </table>
    </applicantSpecific>
  </xsl:template>
  <!--cblcons0 template-->
  <xsl:template match="cblcons0">
    <xsl:param name="index"/>
    <column name="lastUpdated"/>
    <column name="type">
      <xsl:call-template name="cons-type">
        <xsl:with-param name="type" select="type/item[@index = $index]/@data"/>
      </xsl:call-template>
    </column>
    <column name="loanLimit"/>
    <column name="startDate">
      <xsl:value-of select="date/item[@index = $index]/@data"/>
    </column>
    <column name="currentBalance">
      <xsl:if test="balance/item[@index = $index]/@data">
        <xsl:value-of select="balance/item[@index = $index]/@data"/>
      </xsl:if>
    </column>
    <column name="endDate">
      <!-- As we dont have anything other than remaining terms in months decided to leave blank-->
    </column>
    <column name="yearsForOutgoing">
      <xsl:if test="floor(term/item[@index = $index]/@data div 12) != 0">
        <xsl:value-of select="floor(term/item[@index = $index]/@data div 12)"/>
      </xsl:if>
    </column>
    <column name="monthsForOutgoing">
      <xsl:if test="term/item[@index = $index]/@data mod 12 != 0">
        <xsl:value-of select="term/item[@index = $index]/@data mod 12"/>
      </xsl:if>
    </column>
    <column name="monthlyPayment">
      <xsl:if test="repayment/item[@index = $index]/@data != 0">
        <xsl:value-of select="repayment/item[@index = $index]/@data"/>
      </xsl:if>
    </column>
    <column name="purpose">
      <xsl:call-template name="cons-purpose">
        <xsl:with-param name="purpose" select="type/item[@index = $index]/@data"/>
      </xsl:call-template>
    </column>
    <column name="provider">
      <xsl:value-of select="company/item[@index = $index]/@data"/>
    </column>
    <column name="redeemed">
      <xsl:call-template name="boolean-num">
        <xsl:with-param name="indicator" select="settle-amt/item[@index = $index]/@data !=0"/>
      </xsl:call-template>
    </column>
    <column name="securedloan">
      <xsl:call-template name="boolean-num">
        <xsl:with-param name="indicator" select="sec-un/item[@index = $index]/@data = 'S'"/>
      </xsl:call-template>
    </column>
    <column name="shared_outgoing"/>
    <column name="shared_outgoing_app">
      <xsl:if test="client-no/item[@index = $index]/@data = ''"/>
    </column>
    <column name="noEndDate"/>
    <column name="applicantID">{APPLICANTID}</column>
  </xsl:template>
  <!--cblarrs0 template for ccjs-->
  <xsl:template match="cblarrs0" mode="arrs-ccj">
    <xsl:param name="index"/>
    <column name="lastUpdated"/>
    <column name="avcID">{AVCID}</column>
    <column name="lender"/>
    <column name="account_no"/>
    <column name="date">
      <xsl:value-of select="ccj-reg/item[@index = $index]/@data"/>
    </column>
    <column name="date_satisfied"/>
    <!--TODO we only have satisfied Y/N-->
    <column name="monthly_payment"/>
    <column name="total">
      <xsl:if test="ccj-amount/item[@index = $index]/@data != 0">
        <xsl:value-of select="ccj-amount/item[@index = $index]/@data"/>
      </xsl:if>
    </column>
    <column name="monthsSatisfied"/>
  </xsl:template>
  <!--cblarrs0 template for defaults-->
  <xsl:template match="cblarrs0" mode="arrs-def">
    <column name="lastUpdated"/>
    <column name="avcID">{AVCID}</column>
    <column name="lender"/>
    <column name="account_no"/>
    <column name="date">
      <xsl:value-of select="def-reg/item[@index = $index]/@data"/>
    </column>
    <column name="date_satisfied"/>
    <!--TODO we only have satisfied Y/N-->
    <column name="monthly_payment"/>
    <column name="total">
      <xsl:if test="def-costs/item[@index = $index]/@data != 0">
        <xsl:value-of select="def-costs/item[@index = $index]/@data"/>
      </xsl:if>
    </column>
    <column name="monthsSatisfied"/>
  </xsl:template>
</xsl:stylesheet>

[/code]
0
PeterCiuffettiCommented:
Hi,

Without at least an example of the XML, there's still no way to provide a concrete answer.  So the best I can do is provide an example that you will have to adapt to your situation.  In the example below, I provide XSL that counts the number of delinquent paments for each quarter for three different loan applicants in the source XML.

Here is the XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="advances">
<html>
      <head><title>Example of counting</title></head>
      <body>
            <table border="1">
                  <tr>
                        <th>Name</th><th>Payments</th><th>Months 1-3 (#late)</th><th>Months 4-6 (#late)</th><th>Months 7-9 (#late)</th><th>Months 10-12 (#late)</th>
                  </tr>
                  <xsl:for-each select="application">
                        <tr>
                              <xsl:apply-templates select="."/>
                        </tr>
                  </xsl:for-each>
            </table>
      </body>
</html>
</xsl:template>

<xsl:template match="application">
      <td><xsl:value-of select="@name"/></td>
      <td><xsl:value-of select="count(payment)"/></td>
      <td>
            <xsl:value-of select="count(payment[@month = '1' or @month = '2' or @month='3'])"/>
            <xsl:text> (</xsl:text>
                  <xsl:value-of select="count(payment[(@month = '1' and @ontime='n') or (@month = '2' and @ontime='n') or (@month='3' and @ontime='n')])"/>
            <xsl:text>)</xsl:text>
      </td>
      <td>
            <xsl:value-of select="count(payment[@month = '4' or @month = '5' or @month='6'])"/>
            <xsl:text> (</xsl:text>
                  <xsl:value-of select="count(payment[(@month = '4' and @ontime='n') or (@month = '5' and @ontime='n') or (@month='6' and @ontime='n')])"/>
            <xsl:text>)</xsl:text>
      </td>
      <td>
            <xsl:value-of select="count(payment[@month = '7' or @month = '8' or @month='9'])"/>
            <xsl:text> (</xsl:text>
                  <xsl:value-of select="count(payment[(@month = '7' and @ontime='n') or (@month = '8' and @ontime='n') or (@month='9' and @ontime='n')])"/>
            <xsl:text>)</xsl:text>
      </td>
      <td>
            <xsl:value-of select="count(payment[@month = '10' or @month = '11' or @month='12'])"/>
            <xsl:text> (</xsl:text>
                  <xsl:value-of select="count(payment[(@month = '10' and @ontime='n') or (@month = '11' and @ontime='n') or (@month='12' and @ontime='n')])"/>
            <xsl:text>)</xsl:text>
      </td>
</xsl:template>

</xsl:stylesheet>


Here is the test input document example I am using:

<advances>
      <application name="Mr. Good">
            <payment month="1" ontime="y"/>
            <payment month="2" ontime="y"/>
            <payment month="3" ontime="y"/>
            <payment month="4" ontime="y"/>
            <payment month="5" ontime="y"/>
            <payment month="6" ontime="y"/>
            <payment month="7" ontime="y"/>
            <payment month="8" ontime="y"/>
            <payment month="9" ontime="y"/>
            <payment month="10" ontime="y"/>
            <payment month="11" ontime="y"/>
            <payment month="12" ontime="y"/>
      </application>
      <application name="Mr. Marginal">
            <payment month="1" ontime="y"/>
            <payment month="2" ontime="y"/>
            <payment month="3" ontime="n"/>
            <payment month="4" ontime="y"/>
            <payment month="5" ontime="y"/>
            <payment month="6" ontime="y"/>
            <payment month="7" ontime="y"/>
            <payment month="8" ontime="y"/>
            <payment month="9" ontime="y"/>
            <payment month="10" ontime="y"/>
            <payment month="11" ontime="n"/>
            <payment month="12" ontime="y"/>
      </application>
      <application name="Mr. Delinquent">
            <payment month="1" ontime="y"/>
            <payment month="2" ontime="n"/>
            <payment month="3" ontime="y"/>
            <payment month="4" ontime="n"/>
            <payment month="5" ontime="y"/>
            <payment month="6" ontime="n"/>
            <payment month="7" ontime="y"/>
            <payment month="8" ontime="n"/>
            <payment month="9" ontime="y"/>
            <payment month="10" ontime="n"/>
            <payment month="11" ontime="n"/>
            <payment month="12" ontime="n"/>
      </application>
</advances>

When I apply this spreadsheet to the example document, I get the following HTML output:

<html>
  <head>
    <title>Example of counting</title>
  </head>
  <body>
    <table border="1">
      <tr>
        <th>Name</th>
        <th>Payments</th>
        <th>Months 1-3 (#late)</th>
        <th>Months 4-6 (#late)</th>
        <th>Months 7-9 (#late)</th>
        <th>Months 10-12 (#late)</th>
      </tr>
      <tr>
        <td>Mr. Good</td>
        <td>12</td>
        <td>3 (0)</td>
        <td>3 (0)</td>
        <td>3 (0)</td>
        <td>3 (0)</td>
      </tr>
      <tr>
        <td>Mr. Marginal</td>
        <td>12</td>
        <td>3 (1)</td>
        <td>3 (0)</td>
        <td>3 (0)</td>
        <td>3 (1)</td>
      </tr>
      <tr>
        <td>Mr. Delinquent</td>
        <td>12</td>
        <td>3 (1)</td>
        <td>3 (2)</td>
        <td>3 (1)</td>
        <td>3 (3)</td>
      </tr>
    </table>
  </body>
</html>

Now if I wanted to skip a table cell whenever the # of delinquent payments was zero, I would simply have to wrap the count in an xsl:if like

<xsl:if test="count(payment[@month = '1' and ontime="n"]) &gt; 0">
   ...then output the row...
</xsl:if>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paranoidcookieAuthor Commented:
Like I said the xsl is reading a database and the end product is another xml doc which is uploaded to a third party. I will attempt something along the lies you have suggested and get back to you on Monday. Thanks for you help so far.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.