xsl-list
[Top] [All Lists]

Re: [xsl] XSLT 4: map serialization

2020-11-24 21:30:11
So if I have a sequence of maps, such as one gets from using collection()
with the metadata flag set in Saxon, and I want to serialize the result
just to see what is in there, I'd like to be able to use:

Demonstrated how to do this in pure XPath  7 years ago at the Balisage 2013
conference:

https://www.balisage.net/Proceedings/vol10/print/Novatchev01/BalisageVol10-Novatchev01.html#d240124e851

The slides are here:

https://www.balisage.net/Proceedings/vol10/author-pkg/Novatchev01/BalisageVol10-Novatchev01.html

HTH,
Dimtre

On Tue, Nov 24, 2020 at 6:03 PM Graydon graydon(_at_)marost(_dot_)ca <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

So if I have a sequence of maps, such as one gets from using collection()
with the metadata flag set in Saxon, and I want to serialize the result
just to see what is in there, I'd like to be able to use:

<xsl:sequence select="$fileArchive !
map:for-each(.,function($k,$v){element{$k}{$v}})" />

This isn't allowed, because map:for-each() takes an XPath function, rather
than an XQuery function, so it hasn't got access to element constructors.

<xsl:for-each select="$fileArchive">
  <xsl:variable as="map(*)" name="currentEntry" select="." />
  <entry>
    <xsl:for-each select="map:keys($currentEntry)[not(. eq 'fetch')]">
      <xsl:element name="{.}">
        <xsl:sequence select="$currentEntry(.)" />
      </xsl:element>
    </xsl:for-each>
  </entry>
</xsl:for-each>

works fine, but I can't help but feel that it lacks elegance of
expression compared to the map:for-each() construction.

Allowing XQuery anonymous functions would be a large change, but at least
in the map serialization case[1] I have trouble thinking of a better
option.  XQuery functions are at least already well-defined.

[1] I cannot tell you how much I want to be able to pass parameters to a
functioned returned from a map of function items and have that function
return elements for applying-a-style purposes, e.g.

<xsl:sequence
select="$stylesMap($styleTypeName)($stylePropertiesMap($styleName))" />

--
Graydon Saunders  | graydonish(_at_)gmail(_dot_)com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")




-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~----------------------------------------------------------------
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>