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

RE: Challenge: do better than my implementation of "u

Subject: RE: Challenge: do better than my implementation of "update map" and "print map"
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Thu, 29 Aug 2013 09:16:56 +0000
RE:  Challenge: do better than my implementation of  "u
Wow!

Thank you Sean, Dimitre, and Wolfgang.

You are awesome.

Okay, we now have two very fine functions on maps:

1. Update an existing map with another key/value pair

2. Print the contents of a map

Below is a complete, working stylesheet which tests the two map functions.

/Roger
------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:map="http://www.w3.org/2005/xpath-functions/map"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:f="function"
                version="3.0">

    <xsl:template match="/">
        <xsl:variable name="m" select="map{'Linda' := 'Rosie'}" />

        <xsl:variable name="m1" select="f:add-entry-to-map('Sally', 'Betsy',
$m)" />
        <xsl:variable name="m2" select="f:add-entry-to-map('Barb', 'Sue',
$m1)" />
        <xsl:variable name="m3" select="f:add-entry-to-map('Nadia', 'Valerie',
$m2)" />
        <xsl:variable name="m4" select="f:add-entry-to-map('Faye', 'Carol',
$m3)" />

        <xsl:sequence select="f:print-map($m4)" />

        <!-- The output is:
               Linda - Rosie
               Sally - Betsy
               Barb - Sue
               Nadia - Valerie
               Faye - Carol
        -->

    </xsl:template>

    <xsl:function name="f:add-entry-to-map" as="map(xs:anyAtomicType,
item()*)">
        <xsl:param name="key" as="xs:anyAtomicType" />
        <xsl:param name="value" as="item()*" />
        <xsl:param name="m" as="map(xs:anyAtomicType, item()*)" />

        <xsl:sequence select="map:new(($m, map:entry($key, $value)),
map:collation($m) )" />

    </xsl:function>

    <xsl:function name="f:print-map" as="xs:string*">
        <xsl:param name="m" as="map(xs:anyAtomicType, item()*)" />

        <xsl:sequence select="map:keys($m) ! (., ' - ', map:get($m, .))"/>

    </xsl:function>

</xsl:stylesheet>

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.