Transform or split - InterFormNG2

Transform or split

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.


Notes
For splitting an XML file the workflow component, Structural split is highly recommended as it keeps the main nodes (headers) and the structure of the original XML file.

 

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:

NG2WorkflowTransformOrSplit0001

 

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:

NG2WorkflowTransformOrSplit0002


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 example below 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:

NG2WorkflowTransformOrSplit0003


To select a dynamic transform style sheet file via an XPath expression.

Variables in transformations

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>
Info

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.

Sort an XML file

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:

<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.
Split and keep the structure and main nodes of the XML

If you want to split an XML file while you want to keep the structure and the main nodes of the XML, then you should consider the Structural split component. This component splits up the input XML file per node but it will still keep the main nodes and structure of the XML.


 

    • Related Articles

    • Split XML

      This advanced converter workflow component can split up an XML in the payload of the current workflow. The subtree of this workflow component is executed for each splitted XML. It is highly recommended to consider the Structural split component ...
    • Structural split

      This article covers the advanced, converter workflow component, Structural split. This component should normally be used instead of the Split XML component as the structural split normally generates the wanted output. The component can be used if you ...
    • Split spool (complex key)

      A spooled file can be split into smaller files depending on the contents e.g. to split up a larger spooled file with many invoices into individual invoices. If the other spooled file split functions are not enough, then you can consider this workflow ...
    • Spooled file split

      You might want to split up spooled files during InterFormNG2 processing. The reason might be, that the input spooled file may contain multiple documents (e.g. invoices), and that you want to create one PDF file (or email) for each invoice. There are ...
    • Transform a spooled file into XML

      InterFormNG2 can help you to transform a spooled file into XML. In order to do that you first need to load the spooled file in the library in the version 2 format. Next you need to setup a transformation of the spooled file in the designer. This will ...