The transform or split workflow component is able to transform and/or split an input XML file. The subtree of this workflow component is executed for each splitted/transformed XML.
A similar component is the Split XML component, which is only able to split the input file. Here you can also see a video that covers splitting of XML files.
If you just want to transform an XML file, then you should consider the XSL transformation component.
The component has these parameters:
Split XPath
This can be used, if you want to split up an XML file per node in the input file. If you use the path above: /Root/Document on an XML file, that looks like this:
Then you will get 3 output XML files, that contains each the Document subtree - without the common Root and CompanyInfo nodes.
If you want to keep any header nodes in the splitted XML files, then you need to copy this into each subtree before splitting the file.
In this example you can see how you can use XSL stylesheets to keep a header from the original input file in the splitted output files, and how to transform the splitted files.
Transform stylesheet
Here you can specify an xslt stylesheet to transform XML files like the XSL transformation component . If a split XPath path has also been specified, then the input file will be split up prior to this transformation, so any lost header nodes (specified in a Split XPath above) cannot be added with this functionality.
You need to load the stylesheet into the transforms folder of the InterFormNG2 library. You can click on the line or the magnifying glass to select a fixed style sheet. You can also click this icon:
To select a dynamic transform style sheet file via an XPath expression.
You can also use workflow variables in an XSLT file e.g. to insert base64 data into an XML file. You can convert a file into base64 encoding with the workflow component, To base64 and then run a transformation like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:param name="Base64" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/Root/CompanyInfo">
<xsl:copy>
<xsl:copy-of select="node()"/>
<PDF_Base64><xsl:value-of select="$Base64" /></PDF_Base64>
<ReturnCode>OK</ReturnCode>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Please notice, that the workflow variable must be defined as so:
<xsl:param name="Base64" />
(This defines a variable called Base64).
In this line the value of the variable, Base64 is inserted into the node, PDF_Base64.
In InterFormNG2 it is possible to sort an XML file based on a node value.
Let us consider this XML file as a reference:
The aim here is to sort the Document nodes based on the value in the DocumentNo nodes as marked above.
You can use a transformation like the one below to sort it:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<Root>
<xsl:copy-of select="/Root/CompanyInfo"/>
<xsl:for-each select="/Root/Document">
<xsl:sort select="DocumentNo"/>
<Document>
<xsl:copy-of select="*"/>
</Document>
</xsl:for-each>
</Root>
</xsl:template>
</xsl:stylesheet>
To use this transformation you first need to save it into a file e.g. called, Sort.xsl.
Then you can upload it into the Transforms library.
Finally you can use it in your workflow like below:
Here we use the workflow component, XSL transformation to change the payload into the sorted XML.