[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT 4 xsl:with

Subject: Re: XSLT 4 xsl:with
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 21 May 2020 15:11:58 -0000
Re:  XSLT 4 xsl:with
On Thu, May 21, 2020 at 05:58:14AM -0000, Michael Kay mike@xxxxxxxxxxxx scripsit:
> This reminds me that I've been trying to find a good syntax for doing
> 
> <xsl:for-each-member-in-array select="[(1 to 3), (5 to 9), (10 to 20)]">
>    <x>{count(current-member())}</x>
> </xsl:for-each-member-in-array>
> 
> where the result is 
> <x>3<x><x>5</x><x>11</x>
> 
> I have a general distaste for adding more bits and pieces to the dynamic context (current-this() and current-that()). They all clutter the space, they have messy static and dynamic scoping rules, and you often end up binding them to variables anyway. I would prefer to bind explicit variables: in some drafts of XSLT 3.0 we used binding variables on xsl:for-each-group, and that's what saxon:for-each-member currently does:
> 
> https://saxonica.com/documentation/index.html#!extensions/instructions/for-each-member
> 
> <saxon:for-each-member select="[(1 to 3), (5 to 9), (10 to 20)]" bind-to="m">
>    <x>{count($m)}</x>
> </saxon:for-each-member>
> 
> What do other people feel? Should we have @bind-to on other things like xsl:for-each and xsl:for-each-group?

@bind-to as a replacement for current-group() would be fine, but!

I would hate to lose current-grouping-key(); that often winds up being
used as a map key or going into an attribute.  I would expect we could
have a bind-key-to attribute as a replacement for current-grouping-key()

I'd want for-each to have @bind-to as a way to save the context item.  I
presently find myself sticking dot in a variable fairly often, just so I
don't lose it in the contents of the for-each.

I'd like to be able to attach a type to the @bind-to and @bind-key-to
variables, which would mean they'd have to be elements

<xsl:for-each select="1 to 100">
  <xsl:bind-to name="context" as="xs:integer"/>
  ... do stuff....
</xsl:for-each>

If we're considering opening up for-each and for-each-group, some analog to the XQuery "at",

for $x at $count in $stuff

would be welcome.  Don't want it often but it's a pain not to have it
when it is wanted.  I don't have a good feel for for-each-member but
have a suspicion an "at" would be useful there as well.  bind-index,
whether as an attribute or an element?

> The other approach to the above construct is to do it all in XPath. You can also do this in Saxon 10:
> 
> <xsl:sequence select="[(1 to 3), (5 to 9), (10 to 20)] => array:for-each(_{saxon:new-element("x", string(count($1))})"/>

This is powerful and useful and it gets so hard to read.  I'd prefer to
have a "write it out longhand" option as well as the XPath.

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.