Add new test case for inline functions with closures
authorMichael Kay <mike@saxonica.com>
Fri, 04 Dec 2015 09:48:37 +0000
changeset 1187 6c84308066f6
parent 1186 7f4cefa4b568
child 1188 7404bf2099ff
Add new test case for inline functions with closures
tests/expr/higher-order-functions/higher-order-functions-071.xsl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/expr/higher-order-functions/higher-order-functions-071.xsl	Fri Dec 04 09:48:37 2015 +0000
@@ -0,0 +1,43 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:map="http://www.w3.org/2005/xpath-functions/map"
+  version="3.0" exclude-result-prefixes="xs map">
+
+  <xsl:template name="process-map" as="map(*)">
+    <xsl:param name="map" as="map(*)"/>
+    <xsl:param name="operator" as="xs:string"/>
+    <xsl:param name="operand" as="xs:anyAtomicType"/>
+    <xsl:sequence
+      select="map:merge(
+                map:for-each($map, function($k, $v) {
+                  map { $k : if ($operator eq '+') then $v + $operand
+                             else if ($operator eq '-') then $v - $operand
+                             else if ($operator eq '*') then $v * $operand
+                             else if ($operator eq '/') then $v div $operand
+                             else $v }
+                  }))"
+    />
+  </xsl:template>
+
+  <xsl:template name="xsl:initial-template">
+    <xsl:variable name="result" as="map(*)">
+      <xsl:call-template name="process-map">
+        <xsl:with-param name="map" as="map(*)">
+          <xsl:map>
+            <xsl:map-entry key="'a'" select="22"/>
+            <xsl:map-entry key="'b'" select="23"/>
+            <xsl:map-entry key="'c'" select="24"/>
+            <xsl:map-entry key="'d'" select="25"/>
+            <xsl:map-entry key="'e'" select="26"/>
+            <xsl:map-entry key="'f'" select="27"/>
+          </xsl:map>
+        </xsl:with-param>
+        <xsl:with-param name="operator" select="'*'"/>
+        <xsl:with-param name="operand" select="2"/>
+      </xsl:call-template>
+    </xsl:variable>
+    <out><xsl:value-of select="serialize($result, map{'method':'json'})"/></out>
+  </xsl:template>
+
+
+
+</xsl:stylesheet>