Execute XSLT-based actions in the Admin Client.



Actions can be executed in the Admin Client that are based on XSLT. This is based on using the Command XML. The results from an XSLT can be written into a definable element. For this we use the "key" attribute inside the "command" element for the definition of the XML element.

Configuration

A sample server action is stored in the app/modules/samples module to show how to use this mechanism. The command is visible in the Admin Client under the name "XSLT server action sample" and can be activated and configured there. All that is required for configuration is the selection of a suitable transformation resource asset. The command itself is divided into several steps, where XSLT call and client steps (dialogs) alternate. The actual framework is provided by the scriptlet XSLTServerActionScriptlet. Here, the call of the transformation and the data exchange with the command is executed.

Each XSLT command step must have a "key" attribute set. This contains the name (or selector path) to an element in the command XML where the XSLT writes its output. That is, the root element of the transformation's result document is hooked as a child below this element. The target node is created automatically if it does not already exist. If the node already has children, they are removed beforehand. The example script also uses this element for the data transfer to the XSLT. But this is not mandatory, because the XSLT has read access to the whole command. The return of the XSLT can be inserted only below this node. Other components of the command XML cannot be modified from the XSLT.

<?xml version="1.0"?>
<commands currentstep="0">
	<command target="ScriptletManager" scriptlet="modules.lib.XSLTServerActionScriptlet" method="callXSLT" key="data-step1"/>
	<command target="client" method="showdialog" key="dialog1"/>
	<command target="ScriptletManager" scriptlet="modules.lib.XSLTServerActionScriptlet" method="callXSLT" key="data-step2"/>
	<command target="client" method="showdialog" key="dialog2"/>
	<command target="ScriptletManager" scriptlet="modules.lib.XSLTServerActionScriptlet" method="callXSLT" key="data-step3"/>
	<command target="client" method="showdialog" key="dialog3"/>
	<!-- config transformation-key="" /-->
	<!-- data exchange nodes between command and XSLT -->
	<data-step1>
</data-step1>
	<data-step2>
</data-step2>
	<data-step3>
</data-step3>
</commands>
CODE

Within the XSLT the following parameters are available:

  • censhare:command-xml: The entire command XML.
  • censhare:command-step: The "command" node of the current command step.

This can be used to read the "key" attribute if needed.
censhare:command-key-element: The element referenced via "key" in which the result is to be passed.

Example XSLT

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output omit-xml-declaration="no" encoding="UTF-8"/>
	<!-- Parameters -->
	<xsl:param name="censhare:command-xml"/>
	<xsl:param name="censhare:command-step"/>
	<xsl:param name="censhare:command-key-element"/>
	<xsl:variable name="key" select="$censhare:command-step/@key"/>
	<!-- Input of the transformation is the list of selected assets. -->
	<xsl:variable name="assets" select="asset"/>
	<xsl:template match="/">
<xsl:variable name="clientInput" select="$censhare:command-key-element/@input"/>
		<!-- Transformation is called multiple times. Use key attribute of current command step to decide what to do. -->
		<xsl:choose>
<xsl:when test="$key = 'data-step1'"><result message="{concat('First step of action called on assets (', string-join($assets/@name, ', '), ')')}"/><result message="{concat('First step of action called on assets (', string-join($assets/@name, ', '), ')')}"/></xsl:when>
<xsl:when test="$key = 'data-step2'"><result message="{concat('Second step of action. Client input was: "', $clientInput, '"')}"/></xsl:when>
<xsl:when test="$key = 'data-step3'"><result message="{concat('Third step of action. Client input was: "', $clientInput, '"')}"/></xsl:when>
<xsl:otherwise><result message="'Unknown command step "data-step1'"."/></xsl:otherwise></xsl:choose></xsl:template>
</xsl:stylesheet>
CODE



There is no pre-installed example other than the one mentioned. If needed, XSLT commands of this type are currently created and set up individually as part of customizing.