xsl-list
[Top] [All Lists]

RE: [xsl] managing footnotes in nested elements

2007-09-23 22:48:52
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
questions.

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>
  <tr>
   <td>
    <table id=2>
     <tr>
      <td>
       <footnote level="table">..</footnote>
      </td>
     </tr>
    </table>
   </td>
  </tr>
 </table>

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[(_at_)level='table'])" />
 <xsl:variable name="locf" select=
 
"count(descendant::footnote[(_at_)level='table'][generate-id(ancestor::*[name()='
table'](1))=generate-id(.)])" />
 <xsl:if test="$allf > $locf">

but it's not working.

Cheers
Trevor

-----Original Message-----
From: Trevor Nicholls [mailto:trevor(_at_)castingthevoid(_dot_)com] 
Sent: Saturday, 22 September 2007 1:55 a.m.
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] managing footnotes in nested elements

Hi

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" />
</xsl:template>

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

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

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

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

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
not).

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

Cheers
Trevor



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>