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 InterFormNG2 it is possible to sort an XML file based on a node value.
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.
A simple way to split up the input XML file is to use either the Transform or split or the Split XML workflow component:
Here we refer to the /Root/Document path, which you can insert via the magnifying glass on the split component, if you have loaded a sample XML file in the workflow.
A limitation of the split is, that the header data - CompanyInfo, Greeting and Barcode is outside the Document subtrees and thus not included in each of the splitted files, but we can fix that by changing the XML file before the split.
First we need to create a new text file with the extension .xsl, that contains this text:
<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Identity template, copies everything as is -->
-<xsl:template match="@*|node()">
-<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
-</xsl:copy>
</xsl:template>
<!-- Add CompanyInfo to each document -->
-<xsl:template match="Document">
-<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="node()"/>
<xsl:copy-of select="/Root/CompanyInfo"/>
<xsl:copy-of select="/Root/Greeting"/>
<xsl:copy-of select="/Root/Barcode"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This is an XSLT stylesheet, which duplicates the header nodes into each document.
If we now load this stylesheet file into the Library as a transformation, then we can refer to it in the workflow above in an XSL transformation before the split:
We also now save the splitted XML files to the file system to see the result: (The read from file is cut off)
The result is XML files like the one below:
If you now even also want to insert the Root node of the new, splitted files, then you can add it with another XSLT stylesheet with this inside:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Root>
<xsl:apply-templates/>
</Root>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
We can now again load this .xsl file as a transform file in the Library and refer to that in the workflow like below:
The final workflow now looks like this:
And the final XML files looks like this:
We can now finally create PDF files instead of output XML files: