Re: How to output a subset of preceeding nodes

Subject: Re: How to output a subset of preceeding nodes
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 10 Sep 2000 19:34:34 +0100
Steve,

>What I need to do is to process all FN elements located prior to the current
><P> element, BUT after the last set of <FN> elements I already processed!

I guess that your XML looks something like:

<doc>
  <FN id="fn1">
    <P>Footnote 1</P>
  </FN>
  <P id="para1">Paragraph 1</P>
  <section>
    <FN id="fn2">
      <P>Footnote 2</P>
    </FN>
    <H1>Heading</H1>
    <P id="para2">Paragraph 2</P>
  </section>
</doc>

In other words:
(a) FNs are always associated with (and processed alongside) Ps, not with
any other elements
(b) FNs may not immediately precede their respective P

If this is the case, given that your current node is a P element, you can
get the FN elements between it and the previous P using:

  preceding::FN[generate-id(following::P[1]) = generate-id(current())]

In other words:
any FN element that precedes the current element in the source document 
  such that:
    the unique ID for the immediately following P of the FN is the same as
      the unique ID of the current (P) element

[You don't have to generate-id()s if you have some other natural identifier
for the P elements, like an 'id' attribute.]

So, you could probably use something like:

<xsl:template match="P">
  <xsl:apply-templates />
  <xsl:apply-templates select="preceding::FN[generate-id(following::P[1]) = 
                                             generate-id(current())]" />
</xsl:template>

<xsl:template match="FN">
  <p /><xsl:value-of select="P" />
</xsl:template>

The reason I've done away with the 'Dump Footnotes' named template was that
it's not really necessary: you can just select the FNs that you want to
process within the 'P'-matching template as above rather than passing them
as a parameter to a template.  Of course you can change it back if you want
to :)

I hope that helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/


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


Current Thread