xsl-list
[Top] [All Lists]

Re: [xsl] Navigating <xsl:for-each-group> groups

2015-11-16 17:14:50
Hi,

Or (the same again)

preceding-sibling::*[current-group() intersect .]

or more explicitly

preceding-sibling::*[exists(current-group() intersect .]

These are getting at the set backwards, and will depend on things
being kept in relative (document) order. While this is a neat trick,
the check against position() inside for-each select="current-group()"
is more robust since it will work whatever group you have, however
composed in whatever order given.

<xsl:for-each-group ...>

<xsl:variable name="this-group" select="current-group()"/>
<group>
  <xsl:apply-templates select="$this-group" mode="group-member">
    <xsl:with-param name="group" select="$this-group"/>
</group>
</xsl:apply-templates/>

Then the receiving template in mode "group-member" knows to compare
position() inside $group for relative position within the group.

(And this will work as long as you apply templates to all of them at once.)

Kind of a fun problem.

Cheers, Wendell

On Mon, Nov 16, 2015 at 5:25 AM, Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Michael Müller-Hillebrand mmh(_at_)docufy(_dot_)de wrote:


Am 13.11.2015 um 15:54 schrieb Rick Quatro rick(_at_)rickquatro(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>:

As I am processing a for-each-group, I want to check some of the elements
within the group that are before or after the current node. I can use
preceding-sibling and following-sibling axes, but it doesn't seem like
these
are restricted to the current-group. Is there a good way to query what is
before or after the current node of a group, while insuring that the
query
stays within the group? Thanks. -Rick


I would understand your requirement in a way that might be solved by using
something like this:

preceding-sibling::*[. = current-group()]
following-sibling::*[. = current-group()]

I.e. limit the result of your lookup along the preceding-sibling and
following-sibling axes to the current group.



But he did a
  <xsl:for-each-group select="*" group-starting-with="one">

If he had
  <xsl:for-each-group select="*" group-by=".">
then your comparison would make sense.

Or did you want to use the `is` operator e.g.
  preceding-sibling::*[some $item in current-group() satisfies . is $item]
?





-- 
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>