| XQUERY/XSLT API DOCUMENTATION 4.2 |
All XQuery & XSLT Functions MarkLogic Built-In Functions Admin (xdmp:) AppServer (xdmp:) Classifier (cts:) Debug (dbg:) Document Conversion (xdmp:) Extension (xdmp:) Documents, Directories, Properties, and Locks Functions Extension Functions Function Values Functions HTTP Functions JSON Functions MarkLogic Server Functions Search Functions XML Functions XQuery Context Functions XSLT Functions map (map:) Math (math:) Profile (prof:) Search (cts:) cts:query Constructors Functions Geospatial Functions Geospatial Lexicon Functions Lexicon Functions Search Functions Search Clustering Functions Security (xdmp:) Server Monitoring (xdmp:) Spell (spell:) Update (xdmp:) XQuery Library Modules Admin Library (admin:) Actions Functions Appserver Functions Database Functions Forest Functions Group Functions Host Functions Mimetypes Functions Scheduler Functions Alerting (alert:) Elastic Compute Cloud (ec2:) Entity Enrichment (entity:) Flexible Replication (flexrep:) Geospatial Supporting Functions GEO Functions GeoRSS Functions GML Functions KML Functions MCGM Functions Information Studio (info:) Information Studio Developer (infodev:) Library Services (dls:) cts:query Constructor Functions Document Management Functions Document Update Functions Retention Policy Functions XInclude Functions Modular Documents XInclude Functions XPointer Functions PKI (pki:) Plugin (plugin:) Search (search:) Security-sec (sec:) Spelling Dictionary Management (spell:) Thesaurus (thsr:) Triggers (trgr:) Triggers Library (trgr:) WordProcessingML (ooxml:) ZIP Package (ooxml:) CPF Functions Content Processing Framework (cpf:) CSS Conversion (css:) DocBook Conversion (dbk:) Domains (dom:) Excel Conversion (excel:) Generic Conversion (cvt:) Links (lnk:) MSWord Conversion (msword:) PDF Conversion (pdf:) Pipelines (p:) Powerpoint Conversion (ppt:) XHTML Conversion (xhtml:) W3C-Standard Functions Accessor (fn:) AnyURI (fn:) Boolean (fn:) Context (fn:) DurationDateTime (fn:) Error and Trace (fn:) Node (fn:) Numeric (fn:) QName (fn:) Sequence (fn:) String (fn:) XSLT (fn:) W3C XQuery/XSLT Reference W3C XQuery Functions W3C XQuery Language W3C XSLT Language
This page was generated September 12, 2012 6:02 AM | XQuery & XSLT Built-In & Modules Function Reference
Module: Information Studio Developer
The Information Studio Developer API module contains functions that allow you to write custom collectors and transformers. The Information Studio Developer API is installed as the following file: `install_dir/Modules/MarkLogic/appservices/infostudio/infodev.xqy` where `install_dir` is the directory in which MarkLogic Server is installed. To use the `infodev.xqy` module in your own XQuery modules, include the following line in your XQuery prolog:
       import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
               at "/MarkLogic/appservices/infostudio/infodev.xqy";
The library uses the `infodev:` namespace, which is not predefined in the server. MarkLogic recommends enabling the URI Lexicon when using Information Studio; the URI lexicon will improve performance, especially when the database grows to a large number of documents.
Function Summary
infodev:check-options | This function checks the options node to ensure that the structure and values are correct.
infodev:collector-options | This function returns an options node in the xdmp:document-get namespace that is ready to pass into xdmp:document-get, including default-namespace, repair, format, default-language, encoding if they are defined by policy or options.
infodev:effective-policy | This function temporarily resets the specified deltas on the named policy, while leaving the policy itself unchanged.
infodev:file-filter | This function returns a string representing a matching pattern to be applied to file paths on ingest.
infodev:filesystem-walk | This function can be used along with the infodev:ingest function to build custom load operations.
infodev:handle-error | This function provides configuration-aware error handling.
infodev:ingest | This function ingests a single document into the database specified in the ticket, according to the rules defined by the named policy and user-supplied options.
infodev:log-progress | This function writes log information into a ticket's progress file that is written to the App-Services database.
infodev:ticket-add-annotation | This function adds annotation to the specified ticket.
infodev:ticket-create | This function generates a ticket and stores it in the specified database.
infodev:ticket-get-status | This function returns the status of the specified ticket.
infodev:ticket-set-status | This function sets the status of the specified ticket.
infodev:ticket-set-total-documents | This function sets the number of documents to load into the database.
infodev:ticket-set-total-transactions | This function adds and sets the value of a total-transactions element in the specified ticket.
infodev:transaction | This function ingests a batch of documents in a single invoked transaction.
infodev:transaction-size | This function resolves the transaction size parameter based on stored policy and runtime options and returns an integer that represents the maximum number of documents to handled in a single transaction.
Function Detail
infodev:check-options(
| $options as element(info:options)
) as element(info:report)*
Summary: This function checks the options node to ensure that the structure and values are correct. It returns a sequence of report elements. An empty sequence indicates that the options node is correct.
Parameters:
$options : The options node to be checked.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      infodev:check-options(
         <options name="default" xmlns="http://marklogic.com/appservices/infostudio">
            <collection>http://marklogic.com/appservices/infostudio</collection>
            <error-handling>continue-with-warning</error-handling>
            <fab-retention-duration>P30D</fab-retention-duration>
            <file-filter>^[^\.]</file-filter>
            <max-docs-per-transaction>100</max-docs-per-transaction>
            <overwrite>overwrite</overwrite>
            <ticket-retention-duration>P30D</ticket-retention-duration>
            <uri>
             <literal>http://foo</literal>
              <filename/>
              <literal>.</literal>
              <ext/>
           </uri>
          </options>)

    (: Returns an empty sequence if the options node is correct.  Otherwise, errors
       are returned. :)
infodev:collector-options(
| $policy-name as xs:string?,
| $policy-deltas as element(info:options)*
) as element(dg:options)?
Summary: This function returns an options node in the `xdmp:document-get` namespace that is ready to pass into `xdmp:document-get`, including default-namespace, repair, format, default-language, encoding if they are defined by policy or options.
Parameters:
$policy-name : The name of a stored ingestion policy.
$policy-deltas : Zero or more options nodes that override those in the stored or default policy.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      let $options :=
          <options xmlns="http://marklogic.com/appservices/infostudio">
             <format>xml</format>
          </options>

      return
         infodev:collector-options("default", $options)

      =>

      <dg:options xmlns:dg="xdmp:document-get">
        <dg:format>xml</dg:format>
      </dg:options>
infodev:effective-policy(
| $policy-name as xs:string?,
| $policy-deltas as element(info:options)*
) as element(info:options)
Summary: This function temporarily resets the specified deltas on the named policy, while leaving the policy itself unchanged.
Parameters:
$policy-name : The name of the policy to temporily modify.
$policy-deltas : One or more deltas to be applied to the policy.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      let $uri :=
      <options name="default" xmlns="http://marklogic.com/appservices/infostudio">
        <uri>
          <literal>http://docs/</literal>
          <filename/>
          <literal>.</literal>
          <ext/>
        </uri>
      </options>

      let $error:=
      <options name="default" xmlns="http://marklogic.com/appservices/infostudio">
          <error-handling>error</error-handling>
      </options>

      return infodev:effective-policy("default", ($uri, $error))

      (: Returns an options node reflecting different URI and error-handling settings
         in the default policy. :)
infodev:file-filter(
| $policy-name as xs:string?,
| $policy-deltas as element(info:options)*
) as xs:string
Summary: This function returns a string representing a matching pattern to be applied to file paths on ingest.
Parameters:
$policy-name : The name of a stored ingestion policy.
$policy-deltas : Zero or more options nodes that contain a file-filter element. The specified file filter can be any valid XQuery regular expression.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      let $options :=
          <options xmlns="http://marklogic.com/appservices/infostudio">
              <file-filter>^[^\.xml]</file-filter>
          </options>

      return
         infodev:file-filter("default", $options)

      =>

      ^[^\.xml]
infodev:filesystem-walk(
| $dir-path as xs:string,
| $ticket-id as xs:string,
| $function as xdmp:function,
| $policy-deltas as element(info:options)?,
| [$context as item()?]
) as empty-sequence()
Summary: This function can be used along with the `infodev:ingest` function to build custom load operations. This function recurses the specified filesystem directory and uses the policy deltas from the specified ticket to determine which files to select for ingestion. The specified process function can be written to modify the content of files before calling the `infodev:ingest` function to load them into the database.
Parameters:
$dir-path : The directory path to walk.
$ticket-id : The ID of the created ticket.
$function : The process function to apply to each file. This is where you can make modifications to each file before loading them into the database. The function signature must be as follows:
         declare function my:function(
            $document as node(),
            $source-location as xs:string,
            $ticket-id as xs:string,
            $policy-deltas as element(info:options)?,
            $context as item()?)
         as empty-sequence()
$policy-deltas : One or more deltas to be applied to the policy.
$context (optional): User-supplied context that is passed to the process function.
Example:
       xquery version "1.0-ml";

       import module namespace info = "http://marklogic.com/appservices/infostudio"
          at "/MarkLogic/appservices/infostudio/info.xqy";
       import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

       declare function local:process-file(
           $document as node(),
           $source-location as xs:string,
           $ticket-id as xs:string,
           $policy-deltas as element(info:options)?,
           $context as item()?)
         {
           (: You can modify the file here :)
           infodev:ingest($document, $source-location, $ticket-id)
         };

       let $function := xdmp:function(xs:QName("local:process-file"))
       let $annotation := <info:annotation>Loading XML docs</info:annotation>
       let $dir-path := "C:\mydocs\xmldocs"
       let $ticket := infodev:ticket-create(
                          $annotation,
                          "myDB",
                          (),
                          () )

       return infodev:filesystem-walk(
                          $dir-path,
                          $ticket,
    	              $function,
    	              (),
                          () )

      (: This query does the same thing as the info:load function.  You can write the
         process-file function to modify each file in some manner before calling
         the infodev:ingest function. :)
infodev:handle-error(
| $ticket-id as xs:string,
| $context as xs:string,
| $error as element(error:error),
| [$annotation as element(info:annotation)?],
| [$error-log-level as xs:string?]
) as empty-sequence()
Summary: This function provides configuration-aware error handling. If the error is to be logged, a `infodev:error` element is logged to the App-Services database, including document source-location, error code, and other information necessary to find and fix the error. Must be used within a try-catch block.
Parameters:
$ticket-id : The id of the ticket.
$context : The file that generated the error.
$error : The error node caught by MarkLogic Server in the try block.
$annotation (optional): The description of the error.
$error-log-level (optional): The error log level. The possible levels are emergency, alert, critcal, error, warning, notice, info, config, debug, fine, finer, or finest. The default level is info.
Example:
      xquery version "1.0-ml";

      import module namespace info = "http://marklogic.com/appservices/infostudio"
          at "/MarkLogic/appservices/infostudio/info.xqy";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      declare namespace error = "http://marklogic.com/xdmp/error";

      declare function local:load-doc(
         $doc
      ) as xs:string
      {
         let $document := xdmp:document-get($doc)
         let $path := "/xml/my.xml"
         let $annotation := <info:annotation>Adding new docs to newdocs</info:annotation>
         let $ticket := infodev:ticket-create($annotation, "myDB", "default", ())

         let $deltas :=
         <options xmlns="http://marklogic.com/appservices/infostudio">
            <uri>
               <literal>http://test</literal>
               <path/>
               <filename/>
               <literal>.</literal>
               <ext/>
            </uri>
         </options>

         let $ingestion :=
             try {
                  infodev:ingest($document, $path, $ticket),
                  infodev:log-progress(
                    $ticket,
                    <info:annotation>my.xml doc inserted</info:annotation>)
             } catch($e) {
                infodev:handle-error($ticket, $path, $e)
             }
          let $_ := infodev:ticket-set-status($ticket, "completed")
          return (fn:concat($path, " loaded into myDB") )
      };

      local:load-doc("C:\test\my.xml")

      (: Logs any errors encountered when loading my.xml into the database. :)
infodev:ingest(
| $document as node(),
| $path as xs:string,
| $ticket-id as xs:string,
| [$policy-deltas as element(info:options)?],
| [$properties as element()*]
) as xs:string
Summary: This function ingests a single document into the database specified in the ticket, according to the rules defined by the named policy and user-supplied options.
Parameters:
$document : The node to be inserted.
$path : The name of the document and the URI path under which it is to be inserted in the database. In order for the path to be included in the URI, you must have <path/> in the uri portion of your policy:
          <options xmlns="http://marklogic.com/appservices/infostudio">
             <uri>
               <literal/>
               <path/>
               <filename/>
               <literal>.</literal>
               <ext/>
             </uri>
          </options>
$ticket-id : The ID of the ticket created by the `infodev:ticket-create` function.
$policy-deltas (optional): An options node to be used with requests associated with this ticket. It is merged with the effective policy at runtime.
$properties (optional): Any properties you want to set on the document. This does the same thing as the `xdmp:document-set-properties` function.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      let $document := xdmp:document-get("C:\mydocs\xmldocs\my.xml")
      let $path := "/newxml/my.xml"
      let $annotation := <info:annotation>Adding my.xml doc</info:annotation>
      let $ticket := infodev:ticket-create($annotation, "myDB", "default", ())

      let $deltas :=
      <options xmlns="http://marklogic.com/appservices/infostudio">
         <uri>
            <literal>http://testing</literal>
            <path/>
            <filename/>
            <literal>.</literal>
            <ext/>
         </uri>
      </options>

      return
         infodev:ingest($document, $path, $ticket. $deltas)

      (: loads the my.xml file, using the default policy, into the URI,
         http://testing/newxml/my.xml. :)
infodev:log-progress(
| $ticket-id as xs:string,
| $annotation as element(info:annotation),
| [$documents-processed as xs:nonNegativeInteger?],
| [$transactions-completed as xs:nonNegativeInteger?],
| [$error-log-level as xs:string?]
) as empty-sequence()
Summary: This function writes log information into a ticket's progress file that is written to the App-Services database.
Parameters:
$ticket-id : The id of the ticket.
$annotation : The string to place in the annotation element.
$documents-processed (optional): The value to place in the documents-processed element.
$transactions-completed (optional): The value to place in the transactions-completed element.
$error-log-level (optional): The error log level. The possible levels are emergency, alert, critcal, error, warning, notice, info, config, debug, fine, finer, or finest. The default level is info.
Example:
      xquery version "1.0-ml";

      import module namespace info = "http://marklogic.com/appservices/infostudio"
          at "/MarkLogic/appservices/infostudio/info.xqy";
      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      let $annotation := <info:annotation>Load took longer than 10 minutes</info:annotation>

      for $ticket in info:tickets()
        let $time := fn:data(info:ticket($ticket)//info:time-consumed)
        return
          if (fn:minutes-from-duration(xs:duration($time)) gt 10)
          then infodev:log-progress($ticket, $annotation)
          else ()

      (: Change progress annotation on any ticket with a time-consumed value
         over 10 minutes. :)
infodev:ticket-add-annotation(
| $ticket-id as xs:string,
| $annotation as element(info:annotation)
) as empty-sequence()
Summary: This function adds annotation to the specified ticket.
Parameters:
$ticket-id : The id of the ticket to which to add the annotation.
$annotation : A custom annotation element designed to store implementation-specific data.
Example:
      xquery version "1.0-ml";

      import module namespace info = "http://marklogic.com/appservices/infostudio"
          at "/MarkLogic/appservices/infostudio/info.xqy";
      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      let $ticket-id := "/tickets/ticket/10095158268051211232"
      let $annotation := <info:annotation>Adding corrected documents</info:annotation>

      return
        infodev:ticket-add-annotation($ticket-id, $annotation)

      (: Adds an annotation to the specified ticket. :)
infodev:ticket-create(
| $annotation as element(info:annotation)?,
| $database as xs:string?,
| $policy-name as xs:string?,
| $policy-deltas as element(info:options)?
) as xs:string
Summary: This function generates a ticket and stores it in the specified database. It returns the id of the generated ticket.
Parameters:
$annotation : A custom annotation element designed to store implementation-specific data.
$database : The database in which to store the generated ticket.
$policy-name : The name of the policy to be used with requests associated with this ticket. If the name is provided but does not exist, an error is thrown. If no name is provided, a stored default policy is used if available. If neither exists, reasonable global defaults are used.
$policy-deltas : An options node to be used with requests associated with this ticket. It is merged with the effective policy at runtime.
Example:
      xquery version "1.0-ml";

      import module namespace info = "http://marklogic.com/appservices/infostudio"
          at "/MarkLogic/appservices/infostudio/info.xqy";
      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      let $policy :=
      <options name="default" xmlns="http://marklogic.com/appservices/infostudio">
        <collection>http://marklogic.com/appservices/infostudio</collection>
        <error-handling>continue-with-warning</error-handling>
        <fab-retention-duration>P30D</fab-retention-duration>
        <file-filter>^[^\.]</file-filter>
        <max-docs-per-transaction>100</max-docs-per-transaction>
        <overwrite>overwrite</overwrite>
        <ticket-retention-duration>P30D</ticket-retention-duration>
        <uri>
          <literal>http://docs/newdocs/</literal>
          <filename/>
          <literal>.</literal>
          <ext/>
        </uri>
      </options>

      let $annotation := <info:annotation>Adding new docs to newdocs</info:annotation>

      return
        infodev:ticket-create($annotation, "testDB", "default", $policy)

      (: Creates a new ticket. :)
infodev:ticket-get-status(
| $ticket-id as xs:string
) as xs:string
Summary: This function returns the status of the specified ticket.
Parameters:
$ticket-id : The id of the ticket from which to get the status.
Example:
      xquery version "1.0-ml";

      import module namespace info = "http://marklogic.com/appservices/infostudio"
          at "/MarkLogic/appservices/infostudio/info.xqy";
      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      for $ticket in info:tickets()
        return if (infodev:ticket-get-status($ticket) = "completed")
               then info:ticket-delete($ticket)
               else ()

      (: Remove all tickets with the status of 'completed'. :)
infodev:ticket-set-status(
| $ticket-id as xs:string,
| $status as xs:string
) as empty-sequence()
Summary: This function sets the status of the specified ticket.
Parameters:
$ticket-id : The id of the ticket to which to set the status.
$status : The status to set on the ticket. The valid status values are "aborted", "active", "cancelled", "cleared", "completed", "inactive", "unloading", "unloaded", and "unload-aborted".
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      infodev:ticket-set-status("/tickets/ticket/13580249356496860619", "active")

      (: Sets the status of the specified ticket to "active." :)
infodev:ticket-set-total-documents(
| $ticket-id as xs:string,
| $total-documents as xs:unsignedInt
) as empty-sequence()
Summary: This function sets the number of documents to load into the database.
Parameters:
$ticket-id : The id of the ticket.
$total-documents : The number of documents to load into the database.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      infodev:ticket-set-total-documents("/tickets/ticket/13580249356496860619", 5)

      (: Sets the total-documents value in the ticket to 5. :)
infodev:ticket-set-total-transactions(
| $ticket-id as xs:string,
| $total-transactions as xs:unsignedInt
) as empty-sequence()
Summary: This function adds and sets the value of a total-transactions element in the specified ticket.
Parameters:
$ticket-id : The id of the ticket.
$total-transactions : The total-transactions value to set.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      infodev:ticket-set-total-transactions("/tickets/ticket/13580249356496860619", 2)

      (: Adds a <total-transactions> element to the ticket and sets the value to 2. :)
infodev:transaction(
| $document-map as map:map,
| $ticket-id as xs:string,
| $function as xdmp:function,
| $policy-deltas as element(info:options)?,
| $transaction-index as xs:integer,
| $context as item()?,
| [$error-log-level as xs:string?]
) as empty-sequence()
Summary: This function ingests a batch of documents in a single invoked transaction. The batch of documents is contained in `$document-map`. Ingestion is done using a function named by the `$function` parameter.
Parameters:
$document-map : A map containing a batch of documents to be ingested in a single transaction. Map keys are used to construct the URI used to locate the document to be ingested, such as the `$source-location` in the function referenced by the `$function` parameter, below.
$ticket-id : The ID of the created ticket.
$function : The ingestion function to apply to each file. This function should call `infodev:ingest` to insert the document into the database. The function signature of `$function` must be of the pattern:
        declare function my:function(
            $document as node(),
            $source-location as xs:string,
            $ticket-id as xs:string,
            $policy-deltas as element(info:options)?,
            $context as item()?)
         as xs:string+
$policy-deltas : One or more deltas to be applied to the policy.
$transaction-index : An integer representing this transaction's index in a sequence of transactions. This is used in error reporting, to distinguish between transactions.
$context : User-supplied context that is passed to the process function.
$error-log-level (optional): The error log level. The possible levels are emergency, alert, critcal, error, warning, notice, info, config, debug, fine, finer, or finest. The default level is info.
Example:
       xquery version "1.0-ml";

       import module namespace info = "http://marklogic.com/appservices/infostudio"
          at "/MarkLogic/appservices/infostudio/info.xqy";
       import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

       (: Define a process-file function. :)
       declare function local:process-file(
           $document as node(),
           $source-location as xs:string,
           $ticket-id as xs:string,
           $policy-deltas as element(info:options)?,
           $context as item()?)
         {
           (: You can modify the file here :)
           infodev:ingest($document, $source-location, $ticket-id)
         };

       let $function := xdmp:function(xs:QName("local:process-file"))
       let $annotation := <info:annotation>Loading XML Shakespeare docs</info:annotation>

       (: Create a ticket to load contents into the myDB database. :)
       let $ticket := infodev:ticket-create($annotation, "myDB", (), ())

       (: Gather the documents to be loaded into $entries. :)
       let $playdir := "C:\Shakespeare\bill_xml"
       let $entries := for $x in xdmp:filesystem-directory($playdir)//dir:pathname/text()
                                  [ends-with(lower-case(.), ".xml")]
                       return xdmp:document-get($x)

       (: Determine the number of documents; the number of documents to be loaded in each
          transaction, and the total number of transactions needed to load all of the documents. :)
       let $entry-count := fn:count($entries)
       let $transaction-size := 5 (: Typically, this value would be extracted from the policy. :)
       let $total-transactions := ceiling($entry-count div $transaction-size)

       (: Create a map containing the documents to be loaded. :)
       let $transactions :=
            for $i at $index in 1 to $total-transactions
            let $map := map:map()
            let $start :=  (($i -1) *$transaction-size) + 1
            let $finish := min((($start  - 1 + $transaction-size),$entry-count))
            let $put := for $entry in ($entries)[$start to $finish]
    	      (: Create an ID for each document that consists of the date, a number, and a
    	         filename contructed from the title of the play, minus spaces. :)
                  let $title := fn:replace($entry/PLAY/TITLE, " ", "")
                  let $id := fn:concat("/", fn:format-dateTime(fn:current-dateTime(),
    				   "[Y01]-[M01]-[D01]_[H01]-[m01]-[s01]-[f01]") ,
    				   "/", $index ,"/", $title, ".xml")
                return map:put($map,$id,$entry)
            return $map

        (: Create the transactions to load the documents into the database. :)
        let $ingestion :=
            for $transaction at $index in $transactions
            return
               try {
                   infodev:transaction($transaction, $ticket, $function, (), $index,(),())
               } catch($e) {
                   infodev:handle-error($ticket, concat("transaction ",$index), $e)
               }
        (: When the load transactions have completed, set the ticket status to "completed". :)
        let $_ := infodev:ticket-set-status($ticket, "completed")
        return ()

       (: This query creates multiple transactions to load the XML files located in the
          "C:\Shakespeare\bill_xml" directory into the myDB database.  Five documents are
          loaded in each transaction. :)
infodev:transaction-size(
| $policy-name as xs:string?,
| $policy-deltas as element(info:options)*
) as xs:positiveInteger
Summary: This function resolves the transaction size parameter based on stored policy and runtime options and returns an integer that represents the maximum number of documents to handled in a single transaction.
Parameters:
$policy-name : The name of a stored ingestion policy. Uses default policy if none is provided.
$policy-deltas : Zero or more options nodes that override those in the stored or default policy.
Example:
      xquery version "1.0-ml";

      import module namespace infodev = "http://marklogic.com/appservices/infostudio/dev"
          at "/MarkLogic/appservices/infostudio/infodev.xqy";

      infodev:transaction-size("default", ())

      (: Returns the max-docs-per-transaction size set in the default policy. :)

© Copyright 2002-2012 MarkLogic Corporation. All rights reserved.