[MarkLogic Dev General] Passing in a MarkLogic map as an XSLT parameter

Geert Josten Geert.Josten at marklogic.com
Tue Jan 5 02:57:54 PST 2016


In general, all built-in MarkLogic XQuery functions are available by default, you only need to declare the prefix with the correct namespace. For those that would require an xqy import, you can use <xdmp:import-module>

http://docs.marklogic.com/guide/xquery/xslt#id_60484

Docs on all functions:

http://docs.marklogic.com/all

Cheers,
Geert

From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of Bal Krishna Gupta <guptabalk at gmail.com<mailto:guptabalk at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Monday, December 28, 2015 at 1:47 AM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] Passing in a MarkLogic map as an XSLT parameter

Hi David,

Below is the code to list all the key values pairs. Please let me know if you have any questions.

xquery version "1.0-ml";

let $items := map:map()
let $_ := map:put($items, "Car", "$5,300")
let $_ := map:put($items, "Boat", "$23,740")

let $params := map:map()
let $_ := map:put($params, "title", "Items sold")
let $_ := map:put($params, "items", $items)

let $xsl := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:map="http://marklogic.com/xdmp/map"
      version="2.0">
    <xsl:param name="title"/>
    <xsl:param name="items" as="map:map"/>
    <xsl:template match="/">
       <Report>
         <title><xsl:value-of select="$title" /></title>

         <xsl:for-each select="map:keys($items)">
           <item>
             <Name> <xsl:value-of select="."/> </Name>
             <Value> <xsl:value-of select="map:get($items, .)"/> </Value>
           </item>
         </xsl:for-each>
       </Report>
    </xsl:template>
  </xsl:stylesheet>
return
  xdmp:xslt-eval($xsl, document { <foo></foo> }, $params)

Thanks
BK

On Sun, Dec 27, 2015 at 6:08 PM, David Strickland <dstricks at gmail.com<mailto:dstricks at gmail.com>> wrote:
I'm new to XQuery/XPath/XSLT and MarkLogic, so it's totally possible that I'm missing something basic :)

I would like to pass in a set of name/value pairs (i.e. a map) as a single named parameter in an XSLT transformation. There could be zero or more name/value pairs. Something similar to the following (XQuery comments would need to be replaced) ...

<snip>
xquery version "1.0-ml";

let $items := map:map()
let $_ := map:put($items, "Car", "$5,300")
let $_ := map:put($items, "Boat", "$23,740")

let $params := map:map()
let $_ := map:put($params, "title", "Items sold")
let $_ := map:put($params, "items", $items)

let $xsl := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:map="http://marklogic.com/xdmp/map"
      version="2.0">
    <xsl:param name="title"/>
    <xsl:param name="items" as="map:map"/>
    <xsl:template match="/">
       <Report>
         <title><xsl:value-of select="$title" /></title>
         (: for each entry in $items :)
           <Item>
             <Name>(: entry key :)</Name>
             <Value>(: entry value :)</Value>
           </Item>
         (: /////////////////////// :)
       </Report>
    </xsl:template>
  </xsl:stylesheet>

return
  xdmp:xslt-eval($xsl, document { <foo></foo> }, $params)
</snip>

Looking through the mailing list archive I see that a similar question was asked: http://markmail.org/message/d6lj35jvtunnxdmt

Someone replied in the thread saying that "You could pass a map as the value of any variable", but doesn't give the syntax.

Any guidance would be much appreciated.
-David

_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20160105/f7614544/attachment.html 


More information about the General mailing list