[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Navigating groups


Subject: Re: [xsl] Navigating <xsl:for-each-group> groups
From: "Michael Müller-Hillebrand mmh@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 16 Nov 2015 10:16:54 -0000

> Am 13.11.2015 um 15:54 schrieb Rick Quatro rick@xxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>:
>
> 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

Hi 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.

- Michael


>
> XML:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>    <first>First</first>
>    <second>Second</second>
>    <one>Number one</one>
>    <two>Number two</two>
>    <three>Number three</three>
>    <four>Number four</four>
>    <five>Number five</five>
>    <one>Number one2</one>
>    <two>Number two2</two>
>    <four>Number four2</four>
>    <five>Number five2</five>
> </root>
>
> XSLT:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>    exclude-result-prefixes="xs"
>    version="2.0">
>
>    <xsl:output indent="yes"/>
>
>    <xsl:template match="/">
>        <xsl:apply-templates select="root"/>
>    </xsl:template>
>
>    <xsl:template match="root">
>        <xsl:for-each-group select="*" group-starting-with="one">
>            <xsl:call-template name="precGroup">
>                <xsl:with-param name="precGroup" select="current-group()"/>
>            </xsl:call-template>
>        </xsl:for-each-group>
>    </xsl:template>
>
>    <xsl:template name="precGroup">
>        <xsl:param name="precGroup"/>
>        <xsl:for-each select="$precGroup">
>            <xsl:message select="."/>
>        </xsl:for-each>
>    </xsl:template>
>
>    <xsl:template match="*">
>        <xsl:copy-of select="."/>
>    </xsl:template>
> </xsl:stylesheet>


Current Thread