Configure search result export
In censhare Web, users can export the results of their search queries for later use. Specific transformations handle which asset details of a search query are exported to a file. These might be details such as ID, name or version of the assets of any search query. As an administrator, you create these transformations and define what kind of information users may export.
Target group
Administrators
Solution Developers
Purpose
Enable users to export the results of their search queries.
Specify the kind of information that should be collected in a search result file.
Context
Configure XSL transformation for search result export and download.
Prerequisites
You should be familiar with the search functionality in censhare Web.
You should know how to work with XSL transformations in censhare.
Creating new transformations for export search results is only supported in the censhare Client.
Introduction
Exporting search results of any search query is handled using a transformation of the "Module/transformation" asset type. An XSLT file attached to the transformation asset covers the whole process. It creates the export file and downloads it to local storage in a defined format. It captures the search results of any query and determines which kind of asset information is transferred to the search result file.
As an administrator, you may create several transformation assets and add individual XSLT files to them. In the XSLT, you specify the kind of information to be transferred to the search result file. For instance, besides asset ID and name, users might need information on workflow, author, and modification date of the assets queried. In multi-language environments, asset details such as asset type and language might be useful.
You also define the format of the export file, such as XML or CSV.
censhare provides a simple default search result transformation "censhare Web: export search result".
With this transformation, only the name and ID of the assets of a search are exported to an XML file. You can use this as a sample and starting point to create your own individual search result transformations.
When users select "Export search results" from the Actions menu of a search page after performing a search, they can then choose a transformation that best fits their needs.
Create a search result transformation asset
Creating new transformations for search result export is only supported in the censhare Client.
To create a search result transformation asset:
Prepare the XSLT for the search result export according to the samples in section "Example".
Log on to censhare Client.
Create the transformation asset: click the "New Asset" + button and select "New asset", "Module", "Transformation".
On the "General" tab, add a name. Choose a descriptive name that indicates what is exported, for instance, "Export search result: name_ID_version" or "Export search result: workflow".
On the Advanced tab:
As "Application", select "Text Editor".
Click "Resources". Select "Enabled" and "In cached tables". In the "Key" field, enter a unique resource key.
Click the plus button next to "Usages" and select "Export transformation".
Confirm with OK. The asset is created.
Click the "Save" icon and confirm with OK to save the asset. Close the Text Editor. You can also drag-and-drop the XSLT file on the new asset and select "Replace".
The file will be added as master file. The XSLT is displayed on the "General" tab under "Preview".
The transformation is created. It is now available for selection in censhare Web. To check this, select "Export search result" from the Actions menu of any search page. Open the "transformation type" drop-down list. To check, if the desired information is listed in the result file, perform a search, and select the new transformation for export.
XSLT example
In the example, crucial parts of the search result XSLT are described. A complete sample result file is provided as well. The asset information used in this example is asset name, ID, and versions.
Preparing the XSLT
The XSLT for exporting search results handles the export of the desired asset information of the search query results to a file and downloads it. You may use the XSLT from the default "censhare Web: export search result" transformation. With this transformation, only the name and ID of the assets of a search are exported to an XML file. You can adapt it to your needs.
General workflow
The XSLT asks for the search parameter that has been used for the query. The executed query is transferred into the censhare XML query format and stored in a temporary result XML. The XSLT then walks through this result file and picks the desired information from the search results. This information is written to the actual result file.
Initiate the export process
The XSLT asks for the parameter "search" and receives the executed query in the censhare XML query format.
<!-- $search receive the full query xml as a parameter -->
<xsl:param name="search"/>
Create a temporary directory for the result XML
A temporary directory is created to store the results of the query that is executed.
<!--
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')"/>
Specify the asset information to be displayed in the file
The following XSLT executes the query again, walks through the result XML and for each entry, extracts the desired asset properties. You can freely specify which asset properties should be displayed with their values. In the example, asset ID, name, and version are output:
<asset id="{@id}" name="{@name}" version="{@version}"/>
You can add further properties to the list or replace them. You may also define the format in which the results should be displayed.
<xsl:variable name="result">
<result>
<xsl:for-each select=
"cs:asset($search/query)">
<asset id="{@id}" name="{@name}" version="{@version}"/>
/>
</xsl:for-each>
</result>
</xsl:variable>
Transfer the search result XML to a file
The information selected in the previous step is then written to a file.
<!-- 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="$xml"/>
<cs:param name="dest" select="$resultFile"/>
<cs:param name="output">
<output indent="yes"/>
</cs:param>
</cs:command>
Return the file and define the file format
The file is made available to the user. You can define the MIME type of the file using "media-type". In the example, a simple text file is used.
<cs:output href="$resultFile" media-type="'text/xml'"/>
Search result file example
Using the XSLT above, the contents of a search query for "jpg" returns an XML file with an output similar to the following:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<asset id="13241" name="Garden.jpg" version="2"/>
<asset id="13242" name="Humpback Whale.jpg" version="3"/>
<asset id="13252" name="Waterfall.jpg" version="1"/>
<asset id="13841" name="Forest.jpg" version="8"/>
<asset id="13842" name="Frangipani Flowers.jpg" version="3"/>
<asset id="13844" name="Green Sea Turtle.jpg" version="1"/>
...
</result>
XSLT sample file
Below, find a complete sample of an exported search query. The asset information used in this example are asset name, ID and versions.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:cs="http://www.censhare.com/xml/3.0.0/xpath-functions"
xmlns:map="http://ns.censhare.de/mapping"
xmlns:temp="http://ns.censhare.de/elements"
xmlns:func="http://ns.censhare.de/functions"
exclude-result-prefixes="xs xd fn xi cs map temp func" version="2.0">
<xsl:output indent="yes" method="xml" omit-xml-declaration="no" encoding="UTF-8"/>
<xsl:param name="search"/>
<xsl:template match="/">
<!-- create a temporary directory where we can store the 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')"/>
<xsl:variable name="result">
<result>
<xsl:for-each select="cs:asset($search/query)">
<asset id="{@id}" name="{@name}"/>
</xsl:for-each>
</result>
</xsl:variable>
<!-- 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'"/>
</xsl:template>
</xsl:stylesheet>
Result
The XSL transformation for exporting and downloading a search result file has been created. When users select it for exporting, they see the type of asset information you defined in the XSLT.