W3C home > Mailing lists > Public > public-xslt-40@w3.org > January 2021

Re: Processiing arrays in XSLT 4

From: Martin Honnen <martin.honnen@gmx.de>
Date: Sun, 10 Jan 2021 11:23:49 +0100
To: public-xslt-40@w3.org
Message-ID: <dcd00e5d-e241-564b-4f78-b365ddcfc151@gmx.de>
Am 09.01.2021 um 17:38 schrieb Michael Kay:
> It seems a no-brainer to provide an XSLT instruction along the lines
> <xsl:for-each-member select="array">
>    ....
> </xsl:for-each>
> to process the members of a supplied array.
> The question is: within the body of this instruction, how should one refer to the current member of the array?
> Recall that a member of an array can be any sequence, not just a single item.

> An alternative would be to depart from precedent and bind variables:
> <xsl:for-each-member select="array" bind-to="member" position="pos">
>     <xsl:if test="$pos ne 1">,</xsl:if>
>     <xsl:for-each select="$member">
>        ...

This seems to be an XSLT representation of the XPath 4 and XQuery 4 for
member expression additions so I think it will be understood, even if
XSLT has no precedent to bind-to attributes; at least if we see an XPath
understanding to be fundamental to XSLT use.

> That's the way I would do it if it weren't so inconsistent with the way other things are done. Also, many arrays in practice have members that are single items (or perhaps zero-or-one items), and binding "." in those cases seems more intuitive.
> Another possibility is to bind "." to a zero-arity function that returns the current member: so to access the current member you write select=".()". Is that just too weird, or would people get used to it? The attraction is that it doesn't involve inventing any new machinery - no new functions, no additions to the dynamic context, and position() and last() work nicely.

An interesting suggestion but I think the variable binding approach
above is easier to get used to than having to use ".()".
Received on Sunday, 10 January 2021 10:24:04 UTC

This archive was generated by hypermail 2.4.0 : Sunday, 10 January 2021 10:24:05 UTC