RE: [xsl] managing footnotes in nested elements

Subject: RE: [xsl] managing footnotes in nested elements
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Mon, 24 Sep 2007 17:48:05 +1200
Hmm. Perhaps my first message wasn't specific enough! I'm still struggling
with this problem though, so here's an attempt to ask more specific

1. I want to test whether a particular table node (the context node)
contains any descendant footnote elements where (a) the footnote "level"
attribute has the value "table", and (b) the footnote's nearest table
ancestor is the context node.

 <table id=1>
    <table id=2>
       <footnote level="table">..</footnote>

In this case we want to get a false when the context node is table 1, and
true when the context node is table 2.

2. The next step is to generalise this test so that the context node may be
anything, i.e. for the current node, X say, there is at least one footnote
element with its level attribute = "X", and that footnote's nearest ancestor
X is in fact the context node X.

I'm trying to achieve the first version with something like this:

 <xsl:variable name="local" select="name(.)" />
 <xsl:variable name="allf"  select=
    "count(descendant::footnote[@level='table'])" />
 <xsl:variable name="locf" select=
table'](1))=generate-id(.)])" />
 <xsl:if test="$allf > $locf">

but it's not working.


-----Original Message-----
From: Trevor Nicholls [mailto:trevor@xxxxxxxxxxxxxxxxxx] 
Sent: Saturday, 22 September 2007 1:55 a.m.
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] managing footnotes in nested elements


Our documents can include footnotes almost anywhere, but on output (to HTML)
the footnotes can only appear in certain places - at the foot of maybe half
a dozen different elements (e.g. document, section, table). Footnote
elements include a level attribute which determines where the footnote
should appear.

Currently this is achieved with the following XSL 1.0 fragments:

<!-- ================================== -->

<!-- Where appropriate, a template which matches one of these
     major elements concludes with a call to a "local_footnotes"
     template which formats any of the footnotes found within
     that element.
<xsl:template match="...">
 <xsl:call-template name="local_footnotes" />

<!-- Only process footnotes within this element -->
<xsl:template name="local_footnotes">
 <xsl:variable name="local" select="name(.)" />
 <xsl:if test="descendant::footnote[@level=$local]">
  <div class="{$local}-footnotes">

<!-- Note:
     Following assumes footnote content can be placed
     within a para - so no complex footnote structure
<xsl:template match="footnote" mode="footnote">
<xsl:variable name="name">
  <xsl:call-template name="getid" />
 <a name="{$name}" />
  <sup class="footnote-number">
   <xsl:apply-templates select="." mode="number" />
  <xsl:apply-templates />

<!-- Footnotes follow a-1-i sequence -->
<xsl:template match="footnote" mode="number">
  <xsl:when test="@level='document'">
   <xsl:number level="any"
       from="document" format="a"/>
  <xsl:when test="@level='section'">
   <xsl:number level="any"
       from="section" format="1"/>
  <xsl:when test="@level='table'">
   <xsl:number level="any"
       from="table" format="i"/>

<!-- ================================== -->

This is working wonderfully well provided that sections, tables, etc. are
not self-nested. (Z within Y within X is fine, X within X or Y within Y is

So if a (large) table contains within itself a second (small) table which
contains a footnote, then the footnote appears twice: at the "foot" of the
small table and again at the "foot" of the large table.

How do I need to modify the above code in order to process these footnotes
correctly, please?

Thanks for any suggestions


Current Thread