Skip to main content
Skip table of contents

Export asset lists or search results to new assets

Use this sample transformation for enabling users to export their search results directly into new assets in the censhare system.


This transformation works with the censhare Server 2022.2.x and higher.

The purpose of this transformation and its behaviour are described in detail here. Users will be able to save an asset list – e.g., search results –  to a new asset without downloading and uploading any files.


XML
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:corpus="http://www.censhare.com/xml/3.0.0/corpus"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:fn="http://www.w3.org/2005/xpath-functions"
        xmlns:cs="http://www.censhare.com/xml/3.0.0/xpath-functions"
        exclude-result-prefixes="#all">

    <!-- parameters -->
    <xsl:param name="search"/> <!-- full query XML -->
    <xsl:param name="formData"/> <!-- Additional parameters from export form -->

    <!-- root match -->
    <xsl:template match="/">

        <!-- create result XML -->
        <xsl:variable name="result">
            <result>
                <xsl:for-each select="cs:asset($search/query)">
                    <asset id="{@id}" version="{@version}" name="{@name}" type="{@type}" deadline="{@deadline}" workflow-id="{@wf_id}" workflow-step-id="{@wf_step}" workflow-target-id="{@wf_target}"/>
                </xsl:for-each>
            </result>
        </xsl:variable>

        <!-- create a temporary directory where we can store our result file -->
        <xsl:variable name="outDir"/>
        <cs:command name="com.censhare.api.io.CreateVirtualFileSystem" returning="outDir"/>
        <xsl:variable name="resultFile" select="concat($outDir, '/', 'result.xml')"/>

        <!-- write xml to file -->
        <cs:command name="com.censhare.api.io.WriteXML">
            <!-- The source here can be replaced with any xml that should be written into the resultant file -->
            <cs:param name="source" select="$result"/>
            <cs:param name="dest" select="$resultFile"/>
            <cs:param name="output">
                <output indent="yes"/>
            </cs:param>
        </cs:command>

        <!-- return the result (file locator) -->
        <!--cs:output href="$resultFile" media-type="'text/xml'"/-->

        <!--
            Example code to create and return an asset instead of just download result from this script
            comment <cs:output ...  above and uncomment rows below to create an asset with the result, content can still be downloaded from UI
            Result element support following attributes
            assetId => id of asset to be downloaded from UI (also possible to pass the asset as child to result element)
            download => set to "false" to prevent download
            pageUrl => Link to "Open" action for csNotify message (if mising and assetId exists "Open" goes to assetId)
            notifyMessage => Custom notify message
         -->
        
        <xsl:variable name="newXMLAsset" as="element(asset)">
            <asset type="text." name="{$formData/@name}">
                <asset_element idx="0" key="actual."/>
                <storage_item element_idx="0" key="master" mimetype="text/xml" corpus:asset-temp-file-url="{$resultFile}"/>
            </asset>
        </xsl:variable>

        <xsl:variable name="newAsset" as="element(asset)">
          <cs:command name="com.censhare.api.assetmanagement.CheckInNew" >
              <cs:param name="source" select="$newXMLAsset"/>
          </cs:command>
        </xsl:variable>

        <result assetId="{$newAsset/@id}" download="false" />
        
    </xsl:template>

</xsl:stylesheet>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.