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

Re: Processiing arrays in XSLT 4

From: Michael Kay <mike@saxonica.com>
Date: Mon, 11 Jan 2021 08:23:32 +0000
Message-Id: <1EE8E445-F9B2-4A3B-BA4A-1B49CF894F03@saxonica.com>
Cc: public-xslt-40@w3.org
To: Mukul Gandhi <gandhi.mukul@gmail.com>
There are several reasons this doesn't work.

Firstly, an array is a singleton item, so <xsl:for-each select="$array"> is already legal, and processes the array as a single item.

Secondly, the context item is always either a single item or an error, so count(.) either returns 1 or fails.

(We could consider extending the concept of "." so it is a "context value" rather than a "context item". But my instinct is that this would be very disruptive.)

Michael Kay
Saxonica

> On 11 Jan 2021, at 06:59, Mukul Gandhi <gandhi.mukul@gmail.com> wrote:
> 
> On Sat, Jan 9, 2021 at 10:08 PM Michael Kay <mike@saxonica.com <mailto:mike@saxonica.com>> wrote:
> 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.
> 
> I think that, we could even utilize following XSLT idiom for this,
> 
> <xsl:for-each select="array">
>      <xsl:choose>
>            <xsl:when test="count(.) gt 1">
>                 <!-- multi item array member. do something -->
>            </xsl:when>
>            <xsl:otherwise>
>                 <!-- do something -->
>            </xsl:otherwise>
>      </xsl:choose>
> </xsl:for-each> 
>  
> 
> 
> -- 
> Regards,
> Mukul Gandhi


Received on Monday, 11 January 2021 08:23:48 UTC

This archive was generated by hypermail 2.4.0 : Monday, 11 January 2021 08:23:49 UTC