[xsl] generating rows for tables and footnote numbering problem

Subject: [xsl] generating rows for tables and footnote numbering problem
From: "Whitney, Dan (CanWest Interactive)" <DWhitney@xxxxxxxxxxx>
Date: Thu, 8 Jul 2004 10:30:28 -0400
I am generating table rows based on hitting an element attribute value of
<RECORDITEM colname="1">. This is working fine. However I also want to
create numbered footnotes where child elements RECORDREF have same values
for idref attributes. This is where the trouble starts. It works perfectly
for attribute colname with values of 1 but all other values are not working
properly. I really have no idea how to make this work (and yes I have spent
a lot of time trying) so any concrete examples would be much appreciated
 
Thanks in advance,
 
Dan Whitney
 
Here is the XML:
 
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="historicals/histsumm_test.xsl"?>
<!DOCTYPE PUBLICATION
[<!ENTITY % isolat SYSTEM "../xml_isolat1.ent" >
<!ENTITY % isopub SYSTEM "../xml_iso-pub.ent" >
<!ENTITY % isonum SYSTEM "../xml_iso-num.ent" >
%isolat;
%isopub;
%isonum;]>
 
<PUBLICATION>
 
<DOCUMENT source="historicalsummary" product="historicals"
group="historicals">
<RECORD fragment="historicalsummary" recid="2626" fragid="23" status="1"
product="historicals" group="historicals"><ID idtype="fpid">2626</ID>
<RECORDSECTION docfragment="summarytable" rsid="1" desc="table">
<ID idtype="fpid">2626</ID>
<RECORDSECTION docfragment="statistics" desc="historicalsummary"
colformat="colbody">
<RECORDSECTION docfragment="financialperiod" sectionformat="row">
<!--
++++++++++++++++++++++++++++++++
recordref below works fine - "1" is generated
+++++++++++++++++++++++++++++++++
-->
<RECORDITEM sqlsource="element1" colname="1" year="1983"
desc="8029">8,239,030
<RECORDREF idref="2626501" sqlsource="elementnote">Declared following
initial public offering in July 1991.</RECORDREF>
</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="2" year="1983"
desc="8058">5,404,650</RECORDITEM>
<!--
++++++++++++++++++++++++++++++++
recordref does not work although correct number is generated - "2" is
generated
+++++++++++++++++++++++++++++++++
-->
<RECORDITEM sqlsource="element1" colname="3" year="1983"
desc="8120.3">676,265
<RECORDREF idref="2626502" sqlsource="elementnote">Common shares were listed
June 25, 1991.</RECORDREF>
</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="4" year="1983"
desc="8060">4,123,820</RECORDITEM>
<!--
++++++++++++++++++++++++++++++++ 
recordref does not work - "2" is generated - should be a "1"
+++++++++++++++++++++++++++++++++
-->
<RECORDITEM sqlsource="element1" colname="5" year="1983" desc="8082">116,548
<RECORDREF idref="2626501" sqlsource="elementnote">Declared following
initial public offering in July 1991.</RECORDREF>
</RECORDITEM>
<!--
++++++++++++++++++++++++++++++++
recordref does not work although correct number is generated - "2" is
generated
+++++++++++++++++++++++++++++++++
-->
<RECORDITEM sqlsource="element2" colname="6" year="1983" desc="8097.7">n.a.
<RECORDREF idref="2626502" sqlsource="elementnote">Common shares were listed
June 25, 1991.</RECORDREF>
</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="7" year="1983"
desc="8101.7">n.a.</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="8" year="1983"
desc="9052">n.a.</RECORDITEM>
<!--
++++++++++++++++++++++++++++++++ 
recordref does not work - "2" is generated - should be a "1"
+++++++++++++++++++++++++++++++++
-->
<RECORDITEM sqlsource="element2" colname="9" year="1983" desc="9053">n.a.
<RECORDREF idref="2626501" sqlsource="elementnote">Declared following
initial public offering in July 1991.</RECORDREF>
</RECORDITEM>
<!--
++++++++++++++++++++++++++++++++
recordref below works fine - "2" is generated
+++++++++++++++++++++++++++++++++
-->
<RECORDITEM sqlsource="element1" colname="1" year="1984"
desc="8029">9,055,280
<RECORDREF idref="2626502" sqlsource="elementnote">Common shares were listed
June 25, 1991.</RECORDREF>
</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="2" year="1984"
desc="8058">5,888,660</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="3" year="1984"
desc="8120.3">1,011,250</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="4" year="1984"
desc="8060">4,881,290</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="5" year="1984"
desc="8082">251,532</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="6" year="1984"
desc="8097.7">n.a.</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="7" year="1984"
desc="8101.7">n.a.</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="8" year="1984"
desc="9052">n.a.</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="9" year="1984"
desc="9053">n.a.</RECORDITEM>
<!--
++++++++++++++++++++++++++++++++
recordref below works fine - "1" is generated
+++++++++++++++++++++++++++++++++
-->
<RECORDITEM sqlsource="element1" colname="1" year="1985"
desc="8029">8,846,090
<RECORDREF idref="2626501" sqlsource="elementnote">Declared following
initial public offering in July 1991.</RECORDREF>
</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="2" year="1985"
desc="8058">4,866,580</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="3" year="1985"
desc="8120.3">906,269</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="4" year="1985"
desc="8060">5,300,100</RECORDITEM>
<RECORDITEM sqlsource="element1" colname="5" year="1985"
desc="8082">(691,021)</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="6" year="1985"
desc="8097.7">n.a.</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="7" year="1985"
desc="8101.7">n.a.</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="8" year="1985"
desc="9052">n.a.</RECORDITEM>
<RECORDITEM sqlsource="element2" colname="9" year="1985"
desc="9053">n.a.</RECORDITEM>
</RECORDSECTION>
</RECORDSECTION>
</RECORDSECTION>
<RECORDNOTES></RECORDNOTES>
</RECORD>
</DOCUMENT>
</PUBLICATION>
 
Here is the XSL:
 
<xsl:stylesheet
    version="1.0"
    xmlns:xsl=" http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform> ">
 

<xsl:preserve-space elements="text B b P p RECORDITEM"/>
 
<xsl:output
    method="html"
    indent="yes"
    version="4.0"/>
 
<xsl:key match="RECORDREF" name="recref" use="@idref"/>
 

<xsl:template name="process-xml-subset">
   <xsl:param name="xml-subset"/>
   <xsl:if test="$xml-subset[1][@colname &gt; 1]">
     <td align="right">
       <xsl:value-of select="$xml-subset[1]/text()"/>
<!-- apply template to generate footnote numbers in table cells -->
       <xsl:apply-templates
select="$xml-subset[1]/RECORDREF[@sqlsource='elementnote']"/>
     </td>
     <xsl:call-template name="process-xml-subset">
       <xsl:with-param name="xml-subset" select="$xml-subset[position() &gt;
1]"/>
     </xsl:call-template>
   </xsl:if>  
</xsl:template>
 
<xsl:template match="PUBLICATION">
 
  <xsl:apply-templates select="//RECORD [@fragment='historicalsummary']"/>
</xsl:template>
 

<xsl:template match = "RECORD [@fragment='historicalsummary']">
<xsl:for-each select="RECORDSECTION">
  <table class="finstattext" width="600" border="1" cellspacing="0"
cellpadding="2">
      <xsl:for-each select="RECORDSECTION [@colformat='colbody']">
        <xsl:for-each select="RECORDSECTION [@sectionformat='row']">
          <xsl:for-each select="RECORDITEM">
     <xsl:if test="@colname = '1'">
       <tr>
         <td align="left">
           <xsl:value-of select="@year"/>
         </td>
         <td align="right">
           <xsl:copy-of select="text()" />
           <xsl:apply-templates
select="../RECORDITEM/RECORDREF[@idref=current()/RECORDREF/@idref][generate-
id()=generate-id(key('recref',@idref)[1])]"/>
         </td>
  <xsl:call-template name="process-xml-subset">
    <xsl:with-param name="xml-subset"
select="following-sibling::RECORDITEM"/>
  </xsl:call-template>
       </tr>
     </xsl:if>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:for-each>
  </table>
</xsl:for-each>
</xsl:template>
 

<!-- generate footnote number in table cell -->
<xsl:template match="RECORD [@fragment='historicalsummary']//RECORDREF">
  <a href=" #{@idref <mailto:#{@idref> }">
    <sup class="bold">
      <xsl:number
count="RECORDREF[generate-id()=generate-id(key('recref',@idref)[1])]"
format="1" from="RECORD/RECORDSECTION" level="any"/>
    </sup>
  </a>
</xsl:template>
 
<!-- generate footnote number and text and bottom of table -->
<xsl:template match="RECORD [@fragment='historicalsummary']//RECORDREF"
mode="footnote">
  <tr>
    <td colspan="2">
      <a name=" {@idref <mailto:{@idref> }">
        <b>
          <xsl:number
count="RECORDREF[generate-id()=generate-id(key('recref',@idref)[1])]"
format="1. " from="RECORD/RECORDSECTION" level="any"/>
        </b>
        <xsl:value-of select="."/>
      </a>
    </td>
  </tr>
</xsl:template>
 

<xsl:template match="ID" />
<xsl:template match="INDEXENTRY" />
<xsl:template match="XREF" />
</xsl:stylesheet>

An finally here is the html output:
 
<table class="finstattext" width="600" border="1" cellspacing="0"
cellpadding="2">
   <tr>
      <td align="left">1983</td>
      <td align="right">8,239,030
         
         <a href="#2626501"><sup class="bold">1</sup></a></td>
      <td align="right">5,404,650</td>
      <td align="right">676,265
         <a href="#2626502"><sup class="bold">2</sup></a></td>
      <td align="right">4,123,820</td>
      <td align="right">116,548
         <a href="#2626501"><sup class="bold">2</sup></a></td>
      <td align="right">n.a.
         <a href="#2626502"><sup class="bold">2</sup></a></td>
      <td align="right">n.a.</td>
      <td align="right">n.a.</td>
      <td align="right">n.a.
         <a href="#2626501"><sup class="bold">2</sup></a></td>
   </tr>
   <tr>
      <td align="left">1984</td>
      <td align="right">9,055,280
         
         <a href="#2626502"><sup class="bold">2</sup></a></td>
      <td align="right">5,888,660</td>
      <td align="right">1,011,250</td>
      <td align="right">4,881,290</td>
      <td align="right">251,532</td>
      <td align="right">n.a.</td>
      <td align="right">n.a.</td>
      <td align="right">n.a.</td>
      <td align="right">n.a.</td>
   </tr>
   <tr>
      <td align="left">1985</td>
      <td align="right">8,846,090
         
         <a href="#2626501"><sup class="bold">1</sup></a></td>
      <td align="right">4,866,580</td>
      <td align="right">906,269</td>
      <td align="right">5,300,100</td>
      <td align="right">(691,021)</td>
      <td align="right">n.a.</td>
      <td align="right">n.a.</td>
      <td align="right">n.a.</td>
      <td align="right">n.a.</td>
   </tr>
</table>

Current Thread