This extension of the widget 'Include' offers the ability to load dialog definitions from other sources (assets).



Overview

The widget is equipped with a second optional attribute 'expression'. The widget 'Include' offers two optional attributes:

  • key
  • expression

Configuration

When using the attribute 'expression' an XML element "xe:part" is loaded. If more elements are supplied, only the first element is used. The value for the attribute 'expression' stands either for an expression returning an XML document or one (multiple) XML nodes, or it applies directly to a REST URL. In the case of a URL, an entire document is returned. Of these, programmatically the first 'part' element is taken. If you intend to localize the dialogue definitions, the expression for the 'expression' attribute must include a specific transformation URL (see example in next section). The XSLT transformation with the key 'localize' then takes the responsibility for the localization. This transformation is created as an asset of the type "Module · Transformation." The target format is defined as XML text. The transformation includes the following XSLT construct in the master file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:cs="http://www.censhare.com/xml/3.0.0/xpath-functions">

  <xsl:output omit-xml-declaration="no"/>

  <xsl:param name="transform"/>

  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="exists(asset/storage_item[@key='master'])">
        <xsl:variable name="xml-content" select="doc(concat('censhare:///service/assets/asset/id/', asset/@id, '/storage/master/file'))"/>
        <cs:command name="transformation.localization.localize" return-slot="output">
          <xsl:with-param name="input" select="$xml-content"/>
        </cs:command>
      </xsl:when>
      <xsl:otherwise>
        <empty/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
XML


This transformation is loading the asset with dialogue definitions into the input slot. With this slot as parameter, a command to localize the content gets invoked and writes the results into the output slot.

The transformation is capable to perform either a global localization and also inline localization. This requires either global paths and/or the <localization> tag for inline localization to be defined at the text asset with the dialogue definition.
Global resources can be defined within the element '/xml-info/property-resources': 

<xml-info>
 <property-resources>
  <base url="file:common/global"/>
  <base url="file:modules/client/javaclient/module"/>
 </property-resources>
</xml-info>
CODE

Absolute paths are always entered beginning with the first directory that resides under the 'app' directory.

The pairs key/value for inline localization must stand inside the element  <localization>  :

 <localization>
 <properties locale = "en">
 <entry key = "language">Language</entry>
 </properties>
 <properties locale = "de">
 <entry key = "language">Sprache</entry>
 </properties>
 </localization>
           
CODE

Example:


Examples for the definition of the 'expression' attribute:

 <xe:include expression="=:doc('censhare:/service/assets/asset/id/11823/storage/master/file')//xe:part[@id='part2']"/>
 <xe:include expression="=:doc('censhare:/service/assets/asset/id/11823/storage/master/file')//xe:part[1]"/>
 <xe:include expression="=:doc('censhare:/service/assets/asset/id/11823/storage/master/file')"/>
CODE

In the first two examples, a part element gets addressed directly (either by indexation or by id attribute). In the third example, a complete XML document is returned as a result, which consists of a part element or multiple part elements available as children of the root element.
An example of the definition of the 'expression' attribute in a localization:

<xe:include expression="=:doc('censhare:///service/assets/asset/id/11823/transform;key=localize')//xe:part[1]"/>
CODE

Example for assigning the 'expression' attribute to a REST URL:

<xe:include expression="censhare:/service/assets/asset/id/11823/transform;key=localize"/>
CODE

In the dialog definition, which is located in the separate text-asset, the part element or the part elements within a root element must be defined. The name of the root element can be arbitrary. However, it is important that the XML document is valid. The root element must have the prefixes defined. Otherwise, an exception will occur during the evaluation of the dialogue definition. All new functionality is also available without changes in the web client.

Example of the dialog definition in the master file:

 <?xml version="1.0" encoding="UTF-8"?>
<root 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="http://www.censhare.com/xml/3.0.0/dialogs-schema.xsd" 
xmlns:corpus="http://www.censhare.com/xml/3.0.0/corpus" 
xmlns:cs="http://www.censhare.com/xml/3.0.0/xpath-functions" 
xmlns:new-val="http://www.censhare.com/xml/3.0.0/new-val" 
xmlns:new-fct="http://www.censhare.com/xml/3.0.0/new-fct" 
xmlns:xe="http://www.censhare.com/xml/3.0.0/xmleditor">
<xe:part id="test-include-expression" transactional="true">
<xe:group>
<xe:radio-button label="Language" label-style="label-default" align="right" font-size="11" source="@language">
<xe:options label-key="@name" value-key="@id">
<xe:generator name="cachedtables" table-name="language_def"/>
</xe:options>
<xe:listen-to source="@name"/>
</xe:radio-button>
<xe:deletebutton source="@language"/>
</xe:group>
</xe:part>
<xe:part id="part2" transactional="true">
<xe:group>
<xe:scrollpane weight-x="1" height="5em" align="right">
<xe:radio-button label="Language" label-style="label-default" align="right" font-size="11" source="@language" sort="ascending">
<xe:options label-key="@name" value-key="@id">
<xe:generator name="cachedtables" table-name="language_def"/>
</xe:options>
<xe:listen-to source="@name"/>
</xe:radio-button>
</xe:scrollpane>
<xe:deletebutton source="@language"/>
</xe:group>
</xe:part>
</root>
CODE