|
[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
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>
|
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
|

Cart








