Re: [xsl] Rearrange order of processed nodes

Subject: Re: [xsl] Rearrange order of processed nodes
From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 11 Mar 2025 13:07:11 -0000
On 11.03.2025 13:39, Michael Mueller-Hillebrand michael.mueller-hillebrand@xxxxxxxxx wrote:
Yes, I could collect the special elements in a variable and use this.

<xsl:variable name="specialElems" select="(elem1|elem2|elem3|elem4|elem5|elem6)" as="element()+"/>

<xsl:apply-templates select="$specialElems, node() except $specialElems"/>


That's the way I typically tackle this.


Sometimes, if a more complicated sort order is necessary, typically due to schema requirements, I write a sorting function that returns an integer value for each element and then I use xsl:apply-templates/xsl:sort. This sort function might apply itself recursively (with cache="yes") to the preceding sibling of the element in question. Or it might transform its argument in a specific mode so that you don't need to overwrite the whole function if you want to tweak things in an importing stylesheet (the mhhm approach I presented at Balisage 2020 [1]).

Gerrit

[1] https://subversion.le-tex.de/common/presentations/2020-07_Balisage_XSLT_Class-Attributes/slides/index.html#/36

Current Thread