Transform or split

Transform or split

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.

 

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

 

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>

 

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:


<?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.

Split and transforms example:

In this example we will split up this input XML file into multiple PDF files - one for each document:

NG2WorkflowTransformOrSplit0002

A simple way to split up the input XML file is to use either the Transform or split or the Split XML workflow component:

 

NG2SplitXML0003

 

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:

 

NG2SplitXML0004

 

We also now save the splitted XML files to the file system to see the result: (The read from file is cut off)

 

NG2SplitXML0005

 

The result is XML files like the one below:

 

NG2SplitXML0006

 

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:

 

NG2SplitXML0007

 

The final workflow now looks like this:

 

NG2SplitXML0008

 

And the final XML files looks like this:

 

NG2SplitXML0009

 

We can now finally create PDF files instead of output XML files:

 

NG2SplitXML0010

 


    • 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. A similar component, which is also able to transform the splitted files, ...
    • 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 ...
    • Split spool (fixed key position)

      If you want InterFormNG2 to process spooled files, that contains multiple documents e.g. multiple invoices within a single spooled file (e.g. generated by a batch invoice run), then you may want to split up the spooled file into multiple output PDF ...