Thanks, Martin and Hermann. That looks like it will do the trick. I forgot to
state that we're using XSLT 2.
-----Original Message-----
From: Martin Honnen [mailto:Martin(_dot_)Honnen(_at_)gmx(_dot_)de]
Sent: Tuesday, September 14, 2010 10:23 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Preceding siblings test
Hintz, David wrote:
I'm still a novice at XSLT and am having a problem coming up with a test for
elements preceding a particular element, but only up to the first occurrence
of the same (or parent) element. For example, in this XML:
<list>
<a/>
<item>...</item>
<b/><b/><a/>
<item>...</item>
<item>...</item>
<a/><a/>
<item>...</item>
</list>
Assume in this example, <a> and <b> elements can occur before each item (any
number of each). When I start processing an <item>, how do I get a list of
just those nodes before the first preceding <item> or parent <list> element?
With XSLT 2.0 you can use the XPath 2.0 '>>' operator
<xsl:template match="item">
<xsl:variable name="preceding-item"
select="preceding-sibling::item[1]"/>
<xsl:variable name="preceding-abs" select="preceding-sibling:a[.
>> $preceding-item] | preceding-sibling:b[. >>
$preceding-item]"/>
</xsl:template>
It sounds however as if you might want to consider
<xsl:for-each-group select="*" group-ending-with="item">
in a template matching the "list" element. That's also XSLT 2.0 however.
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
--~------------------------------------------------------------------
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>
--~--