Re: [xsl] constructing arrays in XSLT with templates

Subject: Re: [xsl] constructing arrays in XSLT with templates
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 18 Jun 2021 18:44:46 -0000
On 18.06.2021 20:40, Alan Painter alan.painter@xxxxxxxxx wrote:
Hi fellow XSLT enthusiasts,

I've been constructingB json in XSLT using xsl:map and xsl:map-entry and
the resulting code looks really nice.B  But I'm a bit stuck with arrays
and was hoping for some enlightenment.


Within the template for "/books" I find that I have to declare a
variable in order to represent the sequence of maps that come from the
nested apply-templates.

I'd like to be able to do away with the intermediate $books variable
which is used for the purpose of constructing the array using the xpath
"array { ... }" expression.

Is there a more elegant way of doing this?

With Saxon PE and EE there is an extension instruction saxon:array you can use.

And XSLT 4 has some new element doing similar stuff.

But in pure XSLT 3 you need some way to work around the lack of that
instruction so your variable or a function that then does
apply-templates are needed for the general, recursive approach.

Of course for the limited sample you could be tempted to inline anything
as an XPath 3.1 expression.

Current Thread