xsl-list
[Top] [All Lists]

RE: Sort of footnote nodes, processing and counting

2006-02-27 02:48:06
Firstly, I would have thought you can achieve the numbering with something
like

<xsl:number level="any" count="footnote[(_at_)level=current()/@level]"
  from="section|document|table"/>

But this seems to be very similar to what you've tried. It would be useful
if you showed us what numbering this gives and how it differs from the
numbering you want.

Secondly, the infinite recursion. I can't immediately see the reason for
this but running with -T tracing should pin it down.

Michael Kay
http://www.saxonica.com/

 

-----Original Message-----
From: Trevor Nicholls [mailto:trevor(_at_)castingthevoid(_dot_)com] 
Sent: 27 February 2006 07:42
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Sort of footnote nodes, processing and counting

Hi

I am using XSL 2.0 (Saxon 8) to generate HTML files from XML 
data and have
problems with a <footnote> node type.

Before I detail the problems, here's the data model. The XML 
may contain
<footnote> nodes almost anywhere, and the HTML output which I 
am generating
needs to substitute some sort of flag "in-place" and include 
the footnote
content at the end of the high-level element which contains it. Some
footnotes are more local than others, and this is specified 
by an optional
'level' attribute on the footnote element.

Thus:
----
<document>
 <section>
  ...
  <table>
   ...<footnote level="table">...</footnote>...
  </table>
  ...
  <footnote level="document">...</footnote>
  ...
  <footnote>...</footnote>
  ...
  <footnote>...</footnote>
 </section>
</document>
----

The 'level' attribute may be "document", "section", "table" 
or couple of
other high-level elements (and the DTD I am using ensures a default of
"section").

My XSL currently generates output in the right locations, but 
I can't get
precisely what I want.

The critical parts of the XSL:
----
<xsl:template match="/document">
<html>
<head>
  <title><xsl:value-of select="@title" /></title>
</head>
<body>
<h1><xsl:value-of select="@title" /></h1>
<xsl:apply-templates select="section" />
<xsl:call-template name="local_footnotes" />
</body>
</html>
</xsl:template>

<xsl:template match="section">
<xsl:variable name="depth" as="xs:integer">
  <xsl:value-of select="count(ancestor::section)+1" />
</xsl:variable>
<xsl:element name="h{$depth}">
  <xsl:value-of select="@title" />
</xsl:element>
<xsl:apply-templates />
<xsl:call-template name="local_footnotes" />
</xsl:template>

<xsl:template name="local_footnotes">
<xsl:variable name="local" as="xs:string" select="name(.)" />
<xsl:if test="descendant::footnote[(_at_)level=$local]">
  <xsl:apply-templates
    select="descendant::footnote[(_at_)level=$local]" mode="footnote"/>
</xsl:if>
</xsl:template>

<xsl:template match="footnote">
<sup><xsl:number></sup>                <!--  LINE 1 -->
</xsl:template>

<xsl:template match="footnote" mode="footnote">
<p>
<xsl:apply-templates select="." />     <!-- LINE 2 -->
<xsl:apply-templates />
</p>
</xsl:template>
----

The line marked "LINE 1" is far too naive for my purposes; as 
it currently
stands most of the footnote numbers are duplicates because 
the numbering
restarts with every new parent element. However we'll return to this
expression later.

*My first problem*:
while I can generate a footnote number in-place with this 
template, the
attempt (at LINE 2) to repeat that number immediately before 
the footnote
proper is output fails with a stack overflow. I can't figure 
out what I am
doing wrong here (and when I searched the list archives for 
any ideas I saw
exactly this technique being used). So I'm stuck where to go next.

*Secondly*:
actually I want footnotes numbered (and formatted) 
differently in their
separate local sequences within document, section and table 
contexts. I
can't see that any suitable incantation for <xsl:number> 
exists to achieve
this in a single template, but I thought that if I cloned the footnote
template for each sequence then I might be able to do it, viz:
----
<xsl:template match="footnote[(_at_)level='document']">
<sup><xsl:number from="document" format="1"></sup>
</xsl:template>
<xsl:template match="footnote[(_at_)level='section']">
<sup><xsl:number from="section" format="a"></sup>
</xsl:template>
<xsl:template match="footnote[(_at_)level='table']">
<sup><xsl:number from="table" format="i"></sup>
</xsl:template>
----

This doesn't do the job, because the numbering still follows where the
footnote is, not whichever of my "high" levels the footnote 
belongs to. Next
I tried narrowing the count down, like so:
----
<xsl:template match="footnote[(_at_)level='document']">
<sup><xsl:number count="footnote[(_at_)level='document']" from="document"
format="1"></sup>
</xsl:template>
<xsl:template match="footnote[(_at_)level='section']">
<sup><xsl:number count="footnote[(_at_)level='section']" from="section"
format="a"></sup>
</xsl:template>
<xsl:template match="footnote[(_at_)level='table']">
<sup><xsl:number count="footnote[(_at_)level='table']" from="table"
format="i"></sup>
</xsl:template>
----

This changes some of the numbers but they are still wrong 
(and if anything
they are *more* wrong!)

Can somebody please help put me back on the right track here?

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>