This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: saving nodes for later output


David Santamauro wrote:

>I'm not sure how to go about this so here is my qeustion:
>
>I have markup which represents a table and inside the table are footnotes
>and footnote references. I want to save the footnotes (body) outside of the
>table.
>
You do not need to 'save' anything.  Use modes.
There are lots of variations on this technique, but for example:

When you match the table node <tab> do an <xsl:apply-templates/>
followed by <xsl:aply-templates mode="footnotes"/> .

Write templates with no mode attribute which produce the main HTML
table.  When you match the footnote-body bit, output nothing.

Write templates with mode="footnotes" which mostly just do another
apply-templates mode="footnotes".  When you match the footnote-body
bit, output it.

So you do not save anything at all, instead you traverse the input
document twice.  I know that isn't the way you would write a normal
program, but XSLT is not a normal programming language.

BTW I think your XML would be better expressed something like this:

<tab>
 <row>
  <cell id="1">Text with a footnote.<footnote
mark="*">This is the text referred to in cell
id="1"</footnote></cell>
  <cell id ="2">More text...</cell>
 </row>
 <row><cell id="3">&nbsp;</cell></row>
 <row><cell id="4">&nbsp;</cell></row>
</tab>

See how I have put the footnote text where its referenced: I let XSLT
do the work of moving it elswhere on output.  The templates in this
case would include:

<xsl:template match="footnote">
    <a href="#{generate-id()"><sup><xsl:value-of select="@mark"
/></sup></a>
</xsl:template>

<xsl:template match="footnote" mode="footnote">
    <p><a name="{generate-id()"><xsl:value-of select="@mark" /></a>
<xsl:value-of select="'" /></p>
</xsl:template>

Using generate-id() saves you having to put unique labels in the
original document.

If you have lots of footnotes you might want to put the selection of
the footnote mark in the XSLT too.

If you want one footnote to apply to more than one cell then you need
a cross reference, as in

<tab>
 <row>
  <cell id="1">Text with a footnote.<footnote
mark="*" id="x">This is the text referred to in cell
id="1" and "2"</footnote></cell>
  <cell id ="2">More text...<footnote-ref f.id="x"/></cell>
 </row>
 <row><cell id="3">&nbsp;</cell></row>
 <row><cell id="4">&nbsp;</cell></row>
</tab>

To get the '*' marker for a footnote-ref  just means doing what you do
for the footnote element with the matching id:

<xsl:key name="footnotes" match="footnote" use="@id" />
<xsl:template match="footnote-ref">
    <xsl:apply-templates select="key('footnotes', @f.id)" />
</xsl:template>

Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@melvaig.co.uk

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]