[xsl] Stumped: XSL 1.0 recursive template

Subject: [xsl] Stumped: XSL 1.0 recursive template
From: daniel whitney <dbf.whitney@xxxxxxxxx>
Date: Tue, 16 Nov 2010 14:09:44 -0500
Sorry if this gets posted twice ...

I'm stumped. I cannot figure out why the @desc test in the
financialTemp template is always evaluating to true, when the values
being output are different.
I'm simply trying to remove lines with the same desc attribute value
in the RECORDSECTION[@colformat='colbody'] elements.


Here's my XML

<?xml version="1.0" encoding="iso8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<LOOP><RECORD fragment="fp500financial" recid="3282" fragid="34"
product="surveys" status="1" group="surveys" desc="3"><id
idtype="fpid">3282</id>

<RECORDSECTION docfragment="fp500financial"
sectionformat="table"><RECORDSECTION colformat="colhead"
sectionformat="row" desc="perioddate"><RECORDITEM
colname="2">20091231A 1112M20092009US$</RECORDITEM>
<RECORDITEM colname="3">20081231A 1112M20082008US$</RECORDITEM>
</RECORDSECTION>
<RECORDSECTION colformat="colhead" sectionformat="row"
desc="currency"><RECORDITEM colname="1"></RECORDITEM>
<RECORDITEM colname="2">US$</RECORDITEM>
<RECORDITEM colname="3">US$</RECORDITEM>
</RECORDSECTION>
<RECORDSECTION colformat="colbody" sectionformat="row"
desc="60"><RECORDITEM>Revenue - earned premium income</RECORDITEM>
<RECORDITEM sqlsource="element">4422000</RECORDITEM>
<RECORDITEM sqlsource="element">4529100</RECORDITEM>
</RECORDSECTION>
<RECORDSECTION colformat="colbody" sectionformat="row"
desc="60.09"><RECORDITEM>Revenue - interest &amp; other
income</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
</RECORDSECTION>
<RECORDSECTION colformat="colbody" sectionformat="row"
desc="60.09"><RECORDITEM>Revenue - interest &amp; other
income</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
</RECORDSECTION>
<RECORDSECTION colformat="colbody" sectionformat="row"
desc="60.09"><RECORDITEM>Revenue - interest &amp; other
income</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
</RECORDSECTION>
<RECORDSECTION colformat="colbody" sectionformat="row"
desc="80"><RECORDITEM>Net income (loss) after discontinued
operations</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
<RECORDITEM sqlsource="element">1</RECORDITEM>
</RECORDSECTION>
</RECORDSECTION>
</RECORD>
</LOOP>

Here's my XSL

<?xml version="1.0" encoding="iso8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  <xsl:output method="html" indent="yes" version="4.0"/>
  <xsl:template match="LOOP/RECORD">
    <html>
      <body>
        <table>
          <xsl:for-each select="//RECORDSECTION[@colformat='colbody'][1]">
            <xsl:call-template name="financialTemp">
              <xsl:with-param name="nextRecordParam"

select="following-sibling::RECORDSECTION[@colformat='colbody']"/>
              <xsl:with-param name="fincodeParam" select="@desc"/>
            </xsl:call-template>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="financialTemp">
    <xsl:param name="nextRecordParam"/>
    <xsl:param name="fincodeParam"/>

    <xsl:if test="$nextRecordParam[1]">
      <xsl:choose>
        <xsl:when test="$fincodeParam = $nextRecordParam/@desc">
          <tr>
            <td> These are equal</td>
            <td>current fincode <xsl:value-of select="$fincodeParam"/></td>
            <td>next fincode <xsl:value-of
select="$nextRecordParam/@desc"/></td>
          </tr>
        </xsl:when>
        <xsl:otherwise>
          <tr>
            <td> These are NOT equal</td>
            <td>current fincode <xsl:value-of select="$fincodeParam"/></td>
            <td>next fincode <xsl:value-of
select="$nextRecordParam/@desc"/></td>
          </tr>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="financialTemp">
        <xsl:with-param name="nextRecordParam"
select="$nextRecordParam[position() &gt; 1]"/>
        <xsl:with-param name="fincodeParam" select="$nextRecordParam/@desc"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>


And here's my output:

<html>
   <body>
      <table>
         <tr>
            <td> These are NOT equal</td>
            <td>current fincode 60</td>
            <td>next fincode 60.09</td>
         </tr>
         <tr>
            <td> These are equal</td>
            <td>current fincode 60.09</td>
            <td>next fincode 60.09</td>
         </tr>
         <tr>
            <td> These are equal</td>
            <td>current fincode 60.09</td>
            <td>next fincode 60.09</td>
         </tr>
         <tr>
            <td> These are equal</td>
            <td>current fincode 60.09</td>
            <td>next fincode 80</td>
         </tr>
      </table>
   </body>
</html>

Thanks in advance,

Baffled   Dan

Current Thread