Re: [xsl] modes and temp trees (was Re: [xsl] grouping + global variable (?))

Subject: Re: [xsl] modes and temp trees (was Re: [xsl] grouping + global variable (?))
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 17 Aug 2004 15:26:16 +0100
Hi Bruce,

> One remaining problem is how to collapse (Doe, 1999a; Doe, 1999c) into
> (Doe, 1999a, c).  Remindr, in DocBook NG, citations now look like:
>
> <citation>
>     <biblioref linkend="one"/>
>     <biblioref linkend="two"/>
> </citation>
>
> Clearly the problem is something about the if test flagged below. I
> would have thought the position in the current group would get me
> what I want, but it doesn't. If I remove the [...] on the bibref
> variable select statement, however, I can get the collapsing to
> work, but I get all of the document citations.

The test you've got is:

  ../mods:mods[position() = 1]

This tests if the current node's parent has a <mods:mods> element
(whose position is 1 -- this will only and always be true if there's a
<mods:mods> element at all, so the test is equivalent to
"../mods:mods"). Since the current element is a <mods:mods> element,
the test is guaranteed to be true.

What you want is simply:

  <xsl:if test="position() = 1">
    ...
  </xsl:if>

This tests whether the current <mods:mods> element is the first within
the group of <mods:mods> elements that you're looking at.

By the way, you really should be using a key rather than doing:

  //mods:mods[@ID=$idref]

Declare it like:

<xsl:key name="mods" match="mods:mods" use="@ID" />

and use it like:

  <xsl:variable name="bibref" select="key('mods', $idref)" />

Keys are much faster and neater than searching through the entire
document using a predicate. If you rather use a predicate, at least
limit the search by using an explicit path down to the <mods:mods>
elements rather than searching the entire document with //mods:mods.

Cheers,

Jeni

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

Current Thread