On Thu, 2010-10-21 at 10:12 -1000, Brooks Talley wrote:
I've been wresting with this, and my brain is melting. I need to get a
list of the surrounding years for an item -- zero to two years before,
the item itself, zero to two years after. There may be gaps in the
sequence, in which case I still need two items before and after (if
available).
Sample xml:
<root>
<item>
<id>12345</id>
<year>2005</year>
</item>
<otherYears>
<item>
<id>56789</id>
<year>2001<year>
</item>
So e.g. in a template to match /root/item, you might want,
../otherYears/item[ (year - $year) * (year - $year) <= 4 ]
to get the 2 years before or after. However, they might not be there,
so maybe really it's something like,
<xsl:for-each select="../otherYears/item[id = ../../item/id]">
<xsl:apply-templates
select="preceding-sibling::item[position() <= 2]" />
<xsl:apply-templates select="." />
<xsl:apply-templates
select="following-sibling::item[position() <= 2]" />
</xsl:for-each>
Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org
--~------------------------------------------------------------------
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>
--~--