RE: [xsl] generating rows for tables and footnote numbering probl em

Subject: RE: [xsl] generating rows for tables and footnote numbering probl em
From: "Whitney, Dan (CanWest Interactive)" <DWhitney@xxxxxxxxxxx>
Date: Thu, 8 Jul 2004 14:23:36 -0400
Thanks David,

I think I was making that far more complicated than it had to be. Works
great.

Dan

-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: July 8, 2004 12:00 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] generating rows for tables and footnote numbering
probl em




Ah,

the usual trick with cross referencing in xslt is that it's much easier
to make sure that you generate the same number on the reference and at
teh point referenced if you generate both numbers at the
same node, ie first follow the link then make the number.

For the footnte text (which your stylesheet made but didn't call in your
excerpt) you generate the number on the first RECORDREF with each id and
junk teh other cases

so do the same for the ref whatever RECORDREF you are on, go to the
first such before generating the number

<!-- generate footnote number in table cell -->
<xsl:template match="RECORD [@fragment='historicalsummary']//RECORDREF">
  <a href="#{@idref}">
    <sup class="bold">
<xsl:for-each select="key('recref',@idref)[1]">
      <xsl:number
count="RECORDREF[generate-id()=generate-id(key('recref',@idref)[1])]"
format="1" from="RECORD/RECORDSECTION" level="any"/>
</xsl:for-each>
    </sup>
  </a>
</xsl:template>

the for-each here just moves the context it's not really a loop.

here's the whole thing, for completeness.

by teh way beware things like

<xsl:apply-templates select="//RECORD [@fragment='historicalsummary']"/>

as that // means search teh entire document for RECORD nodes. You may
know that RECORDREF isn't going to recursively contain a new RECORD
element, but the system doesn't know that. Giving teh exact path down
from PUBLICATION is likely to make a significant speed improvement.

David


<xsl:stylesheet
    version="1.0"
    xmlns:xsl="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>
<xsl:apply-templates
select=".//RECORDREF[count(.|key('recref',@idref)[1])=1]" mode="footnote"/>
  </table>
</xsl:for-each>
</xsl:template>
 

<!-- generate footnote number in table cell -->
<xsl:template match="RECORD [@fragment='historicalsummary']//RECORDREF">
  <a href="#{@idref}">
    <sup class="bold">
<xsl:for-each select="key('recref',@idref)[1]">
      <xsl:number
count="RECORDREF[generate-id()=generate-id(key('recref',@idref)[1])]"
format="1" from="RECORD/RECORDSECTION" level="any"/>
</xsl:for-each>
    </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}">
        <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>

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread