xsl-list
[Top] [All Lists]

Re: [xsl] constructing arrays in XSLT with templates

2021-06-18 13:44:51
On 18.06.2021 20:40, Alan Painter alan(_dot_)painter(_at_)gmail(_dot_)com wrote:
Hi fellow XSLT enthusiasts,

I've been constructing json in XSLT using xsl:map and xsl:map-entry and
the resulting code looks really nice.  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.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>