xsl-list
[Top] [All Lists]

Re: [xsl] for-each-group

2018-03-28 11:01:02
On 28.03.2018 17:53, Rick Quatro rick(_at_)rickquatro(_dot_)com 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>
--~----------------------------------------------------------------
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>