[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: sean@xxxxxxxxxxxxxxxxx
Date: Wed, 28 Aug 2013 20:45:35 -0600
|
Hi Roger,
I think this would work better ...
<xsl:function name="f:add-entry-to-map" as="map(xs:string, item())">
<xsl:param name="key" as="xs:string" />
<xsl:param name="value" as="item()" />
<xsl:param name="m" as="map(xs:string, item())" />
<xsl:sequence select="map:new( ($m), map:entry($key, $value)))"
/>
</xsl:function>
.. as the map:new() function works on a sequence of maps. Refer to the
example in the spec, entitled "Example: Using a Map as an Index".
Faithfully,
Sean B. Durkin
On 2013-08-28 15:52, Costello, Roger L. wrote:
Hi Folks,
Below is a stylesheet that implements two functions on maps:
1. Update an existing map with another key/value pair
2. Print the contents of a map
I'm mighty proud of these two functions.
But I'm willing to believe that there exists an even better
implementation.
Challenge: can you create a better implementation of these two
functions?
/Roger
---------------------------------------------------------------------------------
<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">
<!-- Test the two map functions -->
<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)" />
</xsl:template>
<xsl:function name="f:add-entry-to-map" as="map(xs:string,
item())">
<xsl:param name="key" as="xs:string" />
<xsl:param name="value" as="item()" />
<xsl:param name="m" as="map(xs:string, item())" />
<xsl:sequence select="map:new((for $i in map:keys($m) return
map:entry($i, map:get($m, $i)), map:entry($key, $value)))" />
</xsl:function>
<xsl:function name="f:print-map" as="xs:string*">
<xsl:param name="m" as="map(xs:string, item())" />
<xsl:for-each select="map:keys($m)">
<xsl:value-of select="." />
<xsl:text> - </xsl:text>
<xsl:value-of select="map:get($m, .)" />
</xsl:for-each>
</xsl:function>
</xsl:stylesheet>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|