Name

cx:collection-manager — Create or update a named collection.

Synopsis

The cx:collection-manager step creates or updates a named collection.

Input portPrimarySequenceContent types
source✔ ✔  
Output portPrimarySequenceContent types
result✔ ✔  
Option nameTypeDefault valueRequired
sourcexs:anyURI ✔ 
stablexs:booleantrue() 
Declaration
1 |<p:declare-step xmlns:p="http://www.w3.org/ns/xproc">
  |   <p:input port="source" sequence="true"/>
  |   <p:output port="result" sequence="true"/>
  |   <p:option name="source" as="xs:anyURI" required="true"/>
5 |   <p:option name="stable" as="xs:boolean" select="true()"/>
  |</p:declare-step>
Errors
CodeDescription
cxerr:XC0003It is a dynamic error (cxerr:XC0003) if any input document does not have a base URI.
cxerr:XC0004It is a dynamic error (cxerr:XC0004) if any input document has the same base URI as any other input document.
cxerr:XC0005It is a dynamic error (cxerr:XC0005) if any input document does not have an XDM item value.
cxerr:XC0006It is a dynamic error (cxerr:XC0006) if an attempt is made to change a previously constructed stable collection.

Description

The scope of a collection is only the pipeline in which it appears. Collections cannot be shared across pipelines by name. (Technically, the limitation is that collections are only shared among steps that have the same Saxon Configuration, but that tends to be individual pipelines.)

Steps that use a named collection must have some implicit or explicit dependency on the cx:collection-manager function.

Every document in the collection must have a unique URI. It is a dynamic error (cxerr:XC0003) if any input document does not have a base URI. It is a dynamic error (cxerr:XC0004) if any input document has the same base URI as any other input document.

All documents must have a value that is an “XDM item”. It is a dynamic error (cxerr:XC0005) if any input document does not have an XDM item value. (It’s not clear that this error is possible in practice, but in theory…)

A collection created with stable set to true() cannot be changed by another call to cx:collection-manager. It is a dynamic error (cxerr:XC0006) if an attempt is made to change a previously constructed stable collection.

Examples

This pipeline adds two documents to a collection, then refers to that collection in XSLT.

 1 |<p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
   |                xmlns:p="http://www.w3.org/ns/xproc"
   |                version="3.0">
   |  <p:import href="https://xmlcalabash.com/ext/library/collection-manager.xpl"/>
 5 |  <p:output port="result"/>
   | 
   |  <cx:collection-manager name="coll" source="http://example.com/c1" stable="false">
   |    <p:with-input>
   |      <p:inline document-properties="map {'base-uri': 'http://example.com/doc1'}"><doc/></p:inline>
10 |      <p:inline document-properties="map {'base-uri': 'http://example.com/doc2'}"><doc/></p:inline>
   |    </p:with-input>
   |  </cx:collection-manager>
   | 
   |  <p:xslt template-name="main" depends="coll">
15 |    <p:with-input port="source">
   |      <p:empty/>
   |    </p:with-input>
   |    <p:with-input port="stylesheet">
   |      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20 |                      version="3.0">
   |        <xsl:template name="main">
   |          <count><xsl:value-of select="count(collection('http://example.com/c1'))"/></count>
   |        </xsl:template>
   |      </xsl:stylesheet>
25 |    </p:with-input>
   |  </p:xslt>
   |</p:declare-step>

The output it produces is <count>2</count>.