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

Re: Map duplicate handling differences

Subject: Re: Map duplicate handling differences
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 9 Dec 2022 16:34:45 -0000
Re:  Map duplicate handling differences
This shortcoming of xsl:map has been noted:

https://github.com/qt4cg/qtspecs/issues/169

Saxon 11 with XSLT 4.0 enabled already supports the proposed on-duplicates
attribute, for example

<xsl:map on-duplicates="function($x, $y){$x}">

which achieves the effect of use-first in map:merge.

Michael Kay
Saxonica

On 9 Dec 2022, at 16:08, Martin Honnen
martin.honnen@xxxxxx<mailto:martin.honnen@xxxxxx>
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>> wrote:


Am 12/9/2022 um 4:51 PM schrieb Michael Mueller-Hillebrand
michael.mueller-hillebrand@xxxxxxxxx<mailto:michael.mueller-hillebrand@docufy
.de>:
Hello Friday folks,

I have noticed that the duplicate handling when constructing maps is different
and I would like to understand the reason.

When using <xsl:map> with <xsl:map:entry> the transformer rejects duplicate
keys with a runtime error.

<xsl:variable name="pairsMap" as="map(xs:string, xs:string)">
    <xsl:map>
       <xsl:for-each select="tokenize($pairsString, ';')">
            <xsl:map-entry key="substring-before(., '=')"
select="substring-after(., '=')"/>
        </xsl:for-each>
    </xsl:map>
</xsl:variable>

When using map:merge() without any extra options it uses duplicates:use-first
(I learned I can turn on brejectb or buse-lastb or bcombineb):

<xsl:variable name="pairsMap" as="map(xs:string, xs:string)"
        select="map:merge(
            for $t in tokenize($pairsString, ';')
                return map:entry(substring-before($t, '='),
substring-after($t, '=')))"/>

Have I overlooked a way to define options in the xsl:map case?
Or is this a subtle way to get us to move to inline XPath?



XSLT 4 is going to remedy that shortcoming, see
https://qt4cg.org/specifications/xslt-40/Overview-diff.html#duplicate-keys and

<!-- Category: instruction -->
<xsl:map
  on-duplicates? = expression >
  <!-- Content: sequence-constructor -->
</xsl:map>

XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email<>)

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.