Zynk Workflow Documentation

The XSLT Transform task accepts an XML input file and transforms it to another format using an XSL transform file. XSL transforms can be used used to convert an XML file to another XML format, HTML, CSV, plain text and many more formats. You can pass through parameters to the XSLT at runtime if your XSLT file supports parameterised inputs. Please note that the task only supports XSLT 1.0, it does not support XSLT 2.0.

A basic tutorial for writing XSL transforms can be found here, and more detailed information can be found at W3 Schools. You can find sample XSLT files in our Github repository.

Settings

Input File

Required
The name of the XML file for processing.

Log File

Optional
The file to write any messages generated by the XSLT to. You can generate messages by using the xsl:message element in your XSLT. If you don’t provide a log file, messages will still be written as debug messages to the logs in Zynk (if debug logging is enabled).

Output File

Required
The name of the resulting processed file.

Parameters

Optional
A collection of parameters to be passed into the XSLT for processing. This is typically used for user defined data such as Company Name and Address when using a common XSLT file such as an Invoice.xslt.

XSLT File

Required
The name of the XSLT file to use for processing.

Zynk Settings

See Common Task Settings

Examples

A sample input file is shown below, which is to be converted to another XML format.

<?xml version="1.0"?>
<Company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <StockTransactions>
        <StockTransaction>
            <UniqueId>1</UniqueId>
            <StockTransactionType>AdjustmentIn</StockTransactionType>
            <StockCode>BOARD001</StockCode>
            <StockTransactionDate>2006-12-31T00:00:00</StockTransactionDate>
            <Reference>STK TAKE</Reference>
            <Details>Whiteboard - Drywipe (900 x 1200)</Details>
            <Qty>2</Qty>
            <CostPrice>15</CostPrice>
            <SalesPrice>0</SalesPrice>
            <StockTransactionNumber>1</StockTransactionNumber>
        </StockTransaction>
    </StockTransactions>
</Company>

A sample XSLT file is shown below, which will be used to transform the input file.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="yes" />

    <xsl:template match="/">
        <Rows>
            <xsl:for-each select="Company/StockTransactions/StockTransaction">
                <xsl:call-template name="ProcessRow" />
            </xsl:for-each>
        </Rows>
    </xsl:template>

    <xsl:template name="ProcessRow">
        <Row>
            <Code><xsl:value-of select="StockCode" /></Code>
            <Type><xsl:value-of select="StockTransactionType" /></Type>
            <Quantity><xsl:value-of select="Qty" /></Quantity>
            <Cost><xsl:value-of select="CostPrice" /></Cost>
        </Row>
    </xsl:template>
    
</xsl:stylesheet>

The output file is shown below:

<?xml version="1.0" encoding="utf-8"?>
<Rows>
  <Row>
    <Code>BOARD001</Code>
    <Type>AdjustmentIn</Type>
    <Quantity>2</Quantity>
    <Cost>15</Cost>
  </Row>
</Rows>

Extensions

The following extension objects and methods are provided for use within your XSLT. See below for an example of how to use them.

Date Functions

Namespace: urn:DateFunctions
Available Since: Zynk Workflow 2.1.4

Date Format

Converts a given string to an XSD date.
DateFormat(string dateString)

Date Format

Converts a given string to a date format of your choice.
DateFormat(string dateString, string format)

Add Days

Converts a given string to an XSD date, and adds a specified number of days.
AddDays(string dateString, double days)

Add Days

Converts a given string to a date format of your choice, and adds a specified number of days.
AddDays(string dateString, double days, string format)

Add Months

Converts a given string to an XSD date, and adds a specified number of months.
AddMonths(string dateString, int months)

Add Months

Converts a given string to a date format of your choice, and adds a specified number of months.
AddMonths(string dateString, int months, string format)

Add Years

Converts a given string to an XSD date, and adds a specified number of years.
AddYears(string dateString, int years)

Add Years

Converts a given string to a date format of your choice, and adds a specified number of years.
AddYears(string dateString, int years, string format)

File Functions

Namespace: urn:FileFunctions
Available Since: Zynk Workflow 2.1.4

File Exists

Checks if a given file exists.
FileExists(string file)

Valid XML

Checks if a given file exists, and contains valid XML data.
ValidXml(string file)

Node Functions

Namespace: urn:NodeFunctions
Available Since: Zynk Workflow 2.1.4

Select

Selects a node based on an XPath expression. Supports dynamically generated XPath expressions.
Select(Node node, string xpath)

Mapping Functions

Namespace: urn:MappingFunctions
Available Since: Zynk Workflow 2.1.8

Map To

Returns the ‘to’ value from the specified Mapping, based on the specified ‘from’ value.
MapTo(string mappingName, string from)

Map From

Returns the ‘from’ value from the specified Mapping, based on the specified ‘to’ value.
MapFrom(string mappingName, string to)

Example Usage

The XSLT below uses the DateFormat method to convert the value of the MyDate node from the input file to another format.

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:df="urn:DateFunctions"> <!-- Declare the namespace of the function(s) 
you want to use here -->

    <xsl:template match="/">
        <!-- Call the function within an XPath expression, prefixing the function name 
        with the namespace you've declared followed by a colon -->
        <Date><xsl:value-of select="df:DateFormat(MyDate, 'yyyy-MM-dd_HH:mm:ss')" /></Date>
    </xsl:template>

</xsl:stylesheet>

Back | Edit on Github