xsl-list
[Top] [All Lists]

Re: [xsl] Feedback on grouping solution

2019-10-26 12:45:15
Hi Martin,

That's an oversight on my part. Any elements outside of step elements have
to be processed individually. Can I change the for-each-group to just group
adjacent <step> elements? Thank you very much.

Rick

-----Original Message-----
From: Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 
Sent: Saturday, October 26, 2019 1:39 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Feedback on grouping solution

On 26.10.2019 19:03, Rick Quatro rick(_at_)rickquatro(_dot_)com wrote:

I need to process the <step> child elements so that the <figure> 
elements are always on the "right" (even-numbered position) in the 
output. Immediate children of the <procedure> do not factor into the 
odd/even sequence.

The first child of each group of adjacent <step> elements starts a new 
odd/even series. To ensure that the each <figure> is in an 
even-numbered position, I want to insert a <spacer> element where it is
required.


Here is my stylesheet. My basic question is: is there a better or more 
efficient way to do this? I really want to master grouping because it 
comes up in a lot of my tasks. Thank you for any input or criticism.

<?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="/procedure">

         <procedure>

             <!-- Group the children of the procedure, keeping 
adjacent steps together. -->

             <xsl:for-each-group select="child::*"
group-adjacent="local-name(.)">

                 <xsl:choose>

                     <xsl:when 
test="current-group()[1][not(self::step)]">

                         <!-- Single element. -->

                         <xsl:apply-templates 
select="current-group()[1]"/>

I don't understand this part, what is supposed to happen with two (or
more) adjacent <note/><note/> or other non step elements? Do you want to
drop any but the first of them?
--~----------------------------------------------------------------
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>