Skip to content

Data Preprocessing and XSLT Syntax

Often it is necessary to rework data for documents. This is not possible in Word itself. Examples are: special totals, complex sorting, address formatting, etc. For these cases, the data source offers the possibility to transform the data before returning it by XSLT. In this case, the data is first loaded on the basis of the data in the DataSource node and then transferred to the Transformation.

Image title

Basic processing sequence


The configuration file must be a combination of data source (DataSource) and Stylesheet in the corresponding namespace.

Sampleconfiguration

The following example summarized DataSource configuration and stylesheet. The Stylesheet adds new nodes and in the XML output.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:ds="http://www.awisto.de/xrm/2013/officeintegration/I18NConfigurableDataSource"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <i18n:DataSource>
        <i18n:CallingUserDataSet />
        <i18n:DefaultDataSet />
    </i18n:DataSource>

    <xsl:template match="/data">
        <customtag>Dies wird der Inhalt eines neuen Knotens mit dem Namen ‚customtag’</customtag>
        <tax><xsl:value-of select="totalamount * 0.19"/></tax>
        <xsl:apply-templates />
    </xsl:template>

    <!--  copy all nodes and all children if nothing specified -->
    <xsl:template match='node()|@*'>
        <xsl:copy><xsl:apply-templates select='node()|@*'/></xsl:copy>
    </xsl:template>
</xsl:stylesheet>

XLST Syntax

To process existing XML-Nodes(e.g. with address data) you need to define them, such as

<xsl:template name="BillToAddress" ></xsl:template>

a new node with the name "BillToAdress" in your XML-Output. Afterwards, you need to define its contend via a preexisting nodename, variable and condition, calculations or programmatic logic.

<xsl:template name="BillToAddress" >
    <xsl:value-of select="billto_name" />
    <xsl:if test="billto_contactname/text() != ''">
      <xsl:value-of select="$CR" />
      <xsl:value-of select="billto_contactname" />
    </xsl:if>
    <xsl:if test="billto_line1/text() != ''">
      <xsl:value-of select="$CR" />
      <xsl:value-of select="billto_line1" />
    </xsl:if>
    <xsl:value-of select="$CR" />
    <xsl:value-of select="billto_postalcode" />
    <xsl:value-of select="$SPACE" />
    <xsl:value-of select="billto_city" />
    <xsl:if test="billto_country/text() != '' and billto_country/text() != 'DEUTSCHLAND'">
      <xsl:value-of select="$CR" />
      <xsl:value-of select="billto_country" />
    </xsl:if>
</xsl:template>

In the above example, the invoice address is composed of the fields billto_name, billto_contactname, billto_line1, billto_postalcode, billto_city and billto_country with line breaks $CR, as is usual for letterhead addresses. The field values ​​are inserted within the node in the XML output in sequence. The line break was previously defined in variable $CR:

  <xsl:variable name="CR">
        <xsl:text><![CDATA[]]></xsl:text>
  </xsl:variable>

Variables are thus addressed within the XSLT description language with a pre-defined dollar symbol. The syntax within the select and test attributes is called XPath. This allows you to select existing nodes or their attributes in an XML document, using extensive selection rules and filters. In addition, the data thus obtained can be analyzed and further processed using mathematical and logical operators and more than 100 standard functions.