[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: for-each-group

Subject: Re: for-each-group
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Mar 2018 16:25:15 -0000
Re:  for-each-group
The logic is basically:

allocate a grouping key which is effectively:

* for figure elements, a unique key

* for everything else, the local name of the element

then put adjacent elements with the same grouping key into the same group.

Perhaps it would be clearer to write

group-adjacent="if (self::figure) then generate-id() else local-name()"

-- the effect would be the same.

Michael Kay
Saxonica

> On 28 Mar 2018, at 17:14, Rick Quatro rick@xxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> My general intent is to group on figure elements. All consecutive siblings
> that aren't <figure>s (<para> or otherwise) should be in their own group.
>
> Michael's solution works, but I am having trouble getting my head around
the
> logic. Thank you Martin and Michael for the quick replies.
>
> Rick
>
>
>
> -----Original Message-----
> From: Martin Honnen martin.honnen@xxxxxx
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Wednesday, March 28, 2018 12:01 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  for-each-group
>
> On 28.03.2018 17:53, Rick Quatro rick@xxxxxxxxxxxxxx wrote:
>
>> I have a <step> element that looks something like this:
>>
>> <steps>
>>
>>   <step>
>>
>>     <para>Intro stuff</para>
>>
>>     <para>More intro stuff</para>
>>
>>     <figure/>
>>
>>     <figure/>
>>
>>     <para>Conclusion stuff</para>
>>
>>     <para>More conclusion stuff</para>
>>
>>   </step>
>>
>> </steps>
>>
>> I want 4 separate groups:
>>
>> 1) First two <para> elements.
>>
>> 2) First <figure>
>>
>> 3) Second <figure>
>>
>> 4) Last two <para> elements.
>
> Can you explain the rules for that result, do you want to group any
adjacent
> "para" element into one group but keep each "figure" element in its own
> group?
>
> In that case you can use
>
>   <xsl:for-each-group select="*" group-adjacent="boolean(self::para)">
>     <xsl:choose>
>        <xsl:when test="current-grouping-key()">
>          <group>
>             <xsl:apply-templates select="current-group()"/>
>          </group>
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:for-each select="current-group()">
>            <group>
>               <xsl:apply-templates select="."/>
>            </group>
>         </xsl:for-each>
>       </xsl:otherwise>
>    </xsl:choose>
>   </xsl:for-each-group>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.