xsl-list
[Top] [All Lists]

Re: [xsl] ordered selection of child elements

2018-03-08 01:06:46
As to Patrik’s question “why”?

1. “Why” in the sense of “where is this behavior specified?”

https://www.w3.org/TR/xpath-31/#id-path-operator

If every evaluation of E2 returns a (possibly empty) sequence of nodes, these sequences are combined, and duplicate nodes are eliminated based on node identity. The resulting node sequence is returned in document order.

2. Why is it specified to behave like this?

Probably because of the deduplication requirement. If the right-hand side expression E2 initially returns the sequences (c, b, a) and (a, b) *and* you want to deduplicate the combined sequence, there will be an ambiguity whether to return (c, a, b) or (c, b, a). With the additional document order requirement it will reduce to (a, b, c) if we assume that this reflects the document order.

3. Which purpose does the deduplication requirement serve?

I think this comes in very handy at times.

As Martin said, you can use the ! operator or a 'for $var in E1 return ($var/a, $var/b)' expression if you want the post-/ evaluation results returned in this particular order and if you don’t want to repeat E1.

Gerrit


Gerrit


On 08/03/2018 07:54, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de wrote:
Am 08.03.2018 um 07:36 schrieb Dr. Patrik Stellmann patrik(_dot_)stellmann(_at_)gdv-dl(_dot_)de:

Hi,

a question more motivated by curiosity than by a real problem:

With

<xsl:sequence select=“a, b“/>

I will get first element a and second element b – no matter of the order within the input document.

But with

<xsl:sequence select=“root/(a, b)“/>

I will get the elements a and b in document order. So this behaves identical to

            <xsl:sequence select=“root/(a | b)“/>

Why?

Of course I could write

<xsl:sequence select=“root/a, root/b“/>

To ensure a specific order. But sometimes the expression of “root” is much more complex so I’d like to avoid writing it twice or putting it in a variable…

You can move to XPath/XSLT 3 and use the "!" operator

   root!(a, b)



XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/225679> (by email <>)

--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>