Hi Sid and others,
Thanks a lot for the feedback. On purpose we chose node() except b& because
we wanted to keep especially processing instructions. It is my understanding
that all node() other than the do-me-first-elements (great name!) are
processed in document order. And yes, simplicity is important, you never know
who nees to understand the code in a few weeks/months time (and it might be
the original author).
A special shout-out to Michael Kay forcing me to think about the latest
advances in XLST/XPath.
Michael M-H
From: Bauman, Syd s.bauman@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, March 11, 2025 5:24 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Rearrange order of processed nodes
I am wondering if anyone else thinks simplicity has its up side:
<xsl:apply-templates select="elem1|elem2|elem3|elem4|elem5|elem6"/>
<xsl:apply-templates select="node() except
(elem1|elem2|elem3|elem4|elem5|elem6)"/>
Or, if you have lots of elements in the 1st set use a variable as suggested in
the OP, or the function suggested by Michael Kay:
<xsl:apply-templates select="*[ not( f:is-ordinary(.) ) ]"/>
<xsl:apply-templates select="node()[ f:is-ordinary(.) ]"/>
Or am I missing something, and those do not produce the same results as the
previous suggestions,\xB9 or are they somehow woefully inefficient? (Because
they certainly seem more readable to me. Although if I were doing this I would
probably use the reverse of the function M. Kay suggested, that is a
f:do-me-first() function. But it should make no difference.)
Note
\xB9 For example, does an extra text node of white space get inserted between
the do-first set and the rest?
________________________________
MMH> Yes, I could collect the special elements in a variable and use this.
MMH>
MMH> <xsl:variable name="specialElems"
select="(elem1|elem2|elem3|elem4|elem5|elem6)" as="element()+"/>
MMH>
MMH> <xsl:apply-templates select="$specialElems, node() except
$specialElems"/>
MMH>
GI> That's the way I typically tackle this.
GI> 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]).
MK> You could have a function with a boolean result to test if an element is
special or ordinary:
MK> <xsl:function name="f:is-ordinary" as="xs:boolean">
MK> <xsl:param name="element" as="element()"/>
MK> <xsl:sequence select="not(self::(elem1 | elem2 | elem3 ...))"/> <!--
4.0 syntax -->
MK> </xsl:function>
MK> and then use this as a sort key:
MK> <xsl:apply-templates select="sort(*, (), f:is-ordinary#1)"/>
MK> etc. Note false sorts before true.
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3481519> (by
email<>)
|