1
let $stylesheet := "abc.xsl"
let $params := map:map()
let $_ := map:put ($params,"col1","abc")
return
xdmp:xslt-invoke(
            $stylesheet, (), $params,
            <options xmlns="xdmp:eval">
                 <template>a:schema</template>
           
            </options>)

abc.xsl

<xsl:template name="a:schema">
          <xsl:param name="collection-uri" as="xs:string" select="$col1"/>
          <xsl:apply-templates select="collection($collection-uri)"/>
       </xsl:template>

In this currently ,we are taking all the document ,which is coming in collection "abc". But I want to add more than one collection in $param map, so that the document which contain ,both collection "abc" and "def" will comes for example :

 | Document| collection
|:---------|:----------:|
| Doc1     | abc, def   |
| Doc2     | abc        |
| Doc3     | abc, def   |

it will pick Doc1 and Doc3

ravvi
  • 117
  • 6
  • Saxon documentation on collection: https://www.saxonica.com/html/documentation/sourcedocs/collections.html See here an example on how to use collection-function: https://stackoverflow.com/a/6138562/3710053 – Siebe Jongebloed Apr 09 '21 at 09:31
  • 1
    It may be better to use "|" rather than "," to ensure de-duplication of documents present in both collections (but again, I don't know MarkLogic). – Michael Kay Apr 09 '21 at 11:21

1 Answers1

2

collection() accepts a sequence of xs:string, but would return any of the documents in either of the collections specified.

If you want only the docs that are in all of the collections specified, you could use cts:search() with a sequence of cts:collection-query() inside of a cts:and-query().

<xsl:template match="/">
  <xsl:param name="collection-uri" as="xs:string*" select="$col1"/>
  <xsl:apply-templates select="cts:search(doc(), cts:and-query(( $collection-uri ! cts:collection-query(.) )))"/>
</xsl:template>

Enable the 1.0-ml dialect, so that you can use the cts built-in functions by adding the following attribute to your xsl:stylesheet element:

xdmp:dialect="1.0-ml"

The $collection-uri param is declared as xs:string, so it will only have one string value. You could change that to be a sequence of strings with either * or + quantifier:

<xsl:param name="collection-uri" as="xs:string*" select="$col1"/> 

and then set the collections on the $col1 param:

let $_ := map:put ($params,"col1", ('abc', 'def'))
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • Hi , please check the updated question,I want those document which contains both collection (abc and def) as using fn:collection(("abc","def")) , those document will also come that contains either abc or def collection. – ravvi Apr 09 '21 at 17:44