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 17:38:08 -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 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?

Current Thread