-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xslt] Constructing arrays #113
Comments
Is |
First, how would this interact with an as= attribute on xsl:for-each and xsl:iterate ? Second, what values other than 'array" make sense? what happens if i say "map"? What is the value for the default behaviour? |
@martin, yes it probably makes sense to put it on xsl:iterate too, though I'm not sure exactly what xsl:break and xsl:on-completion should do. @liam, there is no @as attribute on xsl:for-each or xsl:iterate. The default is form="sequence" which gives the current behaviour. I've sketched out a meaning for form="map" in the proposal. |
I have revised my ideas on how to construct and deconstruct arrays. For background please see my Balisage 2022 paper at https://www.balisage.net/Proceedings/vol27/html/Kay01/BalisageVol27-Kay01.html My current proposal is as follows. First, we introduce a value called a parcel. A parcel is an item that encapsulates an arbitrary sequence. We provide a pair of functions
We'll talk later about exactly how a parcel is represented. We provide a function to decompose an array into a sequence of parcels, and another to compose an array from a sequence of parcels:
With the help of All that remains is to decide exactly where parcels fit into the type system. Possible candidates are:
The choice involves a trade-off between extra complexity in the spec, extra complexity in implementations, and usability. We should consider how much type safety we want to provide, and whether we want to provide convenient ItemType and pattern syntax for matching parcels (and to avoid parcels matching other types inadvertently). I think the approach that might give the best type safety with least disruption to the data model and type system is to use an arity-0 anonymous function with the annotation %parcel. Perhaps for usability we could also define a built-in item type alias fn:parcel-type defined to be equivalent to |
The Balisage paper has no mentioning of
are used. |
Yes, I'm still toying with ideas for names, especially after MSpMcQ's comments/questions at the conference.
Michael Kay
Saxonica
… On 11 Aug 2022, at 13:34, martin-honnen ***@***.***> wrote:
The Balisage paper has no mentioning of array:members and array:from-members, I take it there
array:parcels($array) returns the members of an array as a sequence of parcels
array:of($parcels) creates an array from a sequence of parcels
are used.
—
Reply to this email directly, view it on GitHub <#113 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASIQIRAM6YRQ7YVVNOAOZLVYTXMZANCNFSM5VBELA7Q>.
You are receiving this because you authored the thread.
|
One thing I like about the design of arrays is that they have been considered in the atomization process. When calling a function that expects an atomic value, the members of the array are implicitly atomized: substring([ 'string' ], 3) → ring If parcels are represented as arrays, we would a) introduce no other concept, we’d b) have some symmetry to maps with single entries, and c) the array members could be supplied as arguments to atomizing functions without the invocation of a further function: (: or array:parcels :)
array:members($array) ! substring(., 3) In my opinion, (: build new array from all members of the original array that have a matching number :)
let $array := [ [ 123, 12 ], [ 45 ], [ 123 ] ]
return array:join( array:members($array)[. = 123] ) As can probably be seen, my perspective is pretty XQuery-centric. |
The spec for xsl:array has now been revised and this issue is no longer relevant. |
I've felt for a while that the current proposal for xsl:array is messy. It's both semantically and syntactically messy with it's
composite=yes|no
attribute and thexsl:array-member
child. I've been using it doing XML to JSON conversion and you get a lot of stuff like this:Almost invariably, xsl:array has xsl:for-each or xsl:apply-templates as a child. So how about allowing:
The semantics here is that xsl:for-each delivers an array in which there is one member for each item in the input sequence. This cleanly eliminates the need for
composite=yes|no
andxsl:array-member
: you can create a "composite" array usingwhich delivers
[(1,2), (2,3), (3,4), (4,5), (5,6)]
.The attribute
form="array"
can also appear onxsl:apply-templates
andxsl:for-each-group
. In the latter case each group produces one member of the resulting array:delivers
[(0,1,2,3,4), (5,6,7,8,9)]
The attribute
form="sequence"
is the default and specifies the current behaviour.I've been wondering also about extending this to
form="map"
. In most cases when you construct a map from an input sequence, both the key and the value are functions of the input item. So instead of:we could write:
which strikes me as an improvement...
The text was updated successfully, but these errors were encountered: