Re: [xsl] Feedback on grouping solution

Subject: Re: [xsl] Feedback on grouping solution
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 26 Oct 2019 19:06:18 -0000
On 26.10.2019 19:03, Rick Quatro rick@xxxxxxxxxxxxxx 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 think with XSLT 3 it is possible to use xsl:iterate on the child elements of the adjacent steps found by grouping:

<xsl:mode on-no-match="shallow-copy"/>

    <xsl:template match="procedure">
            <xsl:for-each-group select="*"
                    <xsl:when test="current-grouping-key()">
                        <xsl:iterate select="current-group()/*">
                            <xsl:param name="position-in-output"
                            <xsl:apply-templates select=".">
name="position-in-output" select="$position-in-output"/>
                                <xsl:with-param name="position-in-output"
                                    select="if (self::figure and
$position-in-output mod 2 = 1)
                                            then $position-in-output + 2
                                            else $position-in-output + 1"/>
                        <xsl:apply-templates select="current-group()"/>

    <xsl:template match="step/figure">
        <xsl:param name="position-in-output"/>
        <xsl:if test="$position-in-output mod 2 = 1">

Now waiting for Dimitre posting a less "fancy" but equally compact XSLT
1 solution :)

Current Thread