Re: mapping (Was: Re: [xsl] Re: . in for)

Subject: Re: mapping (Was: Re: [xsl] Re: . in for)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 8 Jan 2002 19:58:35 +0000
Hi Dave,

>> > This example could be handled with a mapping operator:
>> >
>> >   <xsl:variable name="emps"
>> >     select="//employee[@dept = ($departments -> lower-case(.))]" />
>
> +1 on mapping, but I dislike the above syntax Jeni.
> Scheme gives (map fn sequence).
>
> How about 
>
> select='map lower-case(.) $departments'/>
> or
> select='map (lower-case(.) $departments)'/>
>
> or does this go against the idea of extending keywords?

Well, neither follows the pattern of other operators/keywords in the
XPath 2.0 WD (in particular the second will get confusing because it
looks like a function but without a comma between the arguments) The
closest would be something like:

  map lower-case(.) over $departments

but this organisation doesn't make it particularly easy to pipe
functions together (or at least not in a similar way to location
paths). Using the example:

  $coordinates -> (. * 2)
               -> if (position() mod 2) then . + 50 else .

I think that the above syntax would be:

  map (if (position() mod 2) then . + 50 else .) over
  map (. * 2) over $departments

Personally, I find that hard to follow, but it may be a factor of what
other languages you're used to.

If you want keywords, we could keep the for expression, just drop the
range variable, so that you had:

  for $departments return lower-case(.)

and:

  for (for $coordinates return (. * 2))
  return if (position() mod 2) then . + 50 else .

Or if you just don't like the -> then there are still a few ASCII
characters left, and several interesting combinations of them, or
there's always a word (or two) as the operator, like 'map':

  $departments map lower-case(.)

and:

  $coordinates map (. * 2)
               map if (position() mod 2) then . + 50 else .
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread