|
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 |
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:template match="procedure">
<xsl:copy>
<xsl:for-each-group select="*"
group-adjacent="boolean(self::step)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:iterate select="current-group()/*">
<xsl:param name="position-in-output"
select="1"/>
<xsl:apply-templates select=".">
<xsl:with-param
name="position-in-output" select="$position-in-output"/>
</xsl:apply-templates>
<xsl:next-iteration>
<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:next-iteration>
</xsl:iterate>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template> <xsl:template match="step/figure">
<xsl:param name="position-in-output"/>
<xsl:if test="$position-in-output mod 2 = 1">
<spacer/>
</xsl:if>
<xsl:next-match/>
</xsl:template>Now waiting for Dimitre posting a less "fancy" but equally compact XSLT 1 solution :)
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Feedback on grouping solu, Rick Quatro rick@xxx | Thread | Re: [xsl] Feedback on grouping solu, Dimitre Novatchev dn |
| Re: [xsl] Feedback on grouping solu, Rick Quatro rick@xxx | Date | Re: [xsl] Feedback on grouping solu, Dimitre Novatchev dn |
| Month |