Flexi2XML can also be used as a conversion tool for importing and exporting data from/to ABRA Flexi. It can open a file, convert it to XML, apply conversion tools to it, and write XML again. This works in both directions.
More Complex Conversions from XLS to Flexi
Flexi includes basic import options from XLS (Excel). For more complex cases, it is necessary to use the Flexi2XML tool.
Conversion from Excel
The Flexi2XML tool can directly read XLS files (and therefore also the REST API). Consider the following XLS:
Price List | Customer | Price |
8593026341407 | FLEXI | 1000.0 |
8593026341407 | ARIT | 900.0 |
8593026341407 | VFH | 1050.0 |
8593026341407 | ABRA | 1100.0 |
Conversion from XLS to XML
To proceed with further processing, you need to generate XML as follows (on Linux/Mac OS X, use ";" instead of the ; character):
flexibee2xml --from-xls soubor.xls --evidence odberatel --to-xml soubor.xml
The result is the following XML:
<?xml version="1.0" encoding="utf-8"?><winstrom version="1.0"> <odberatel> <Ceník>8593026341407</Ceník> <Odběratel>FLEXI</Odběratel> <Cena>1000.0</Cena> </odberatel> <odberatel> <Ceník>8593026341407</Ceník> <Odběratel>ARIT</Odběratel> <Cena>900.0</Cena> </odberatel> <odberatel> <Ceník>8593026341407</Ceník> <Odběratel>VFH</Odběratel> <Cena>1050.0</Cena> </odberatel> <odberatel> <Ceník>8593026341407</Ceník> <Odběratel>ABRA</Odběratel> <Cena>1100.0</Cena> </odberatel></winstrom>
If the column names in the XLS file directly matched the attribute names in FlexiXML, we would be done (this is exactly how CSV and XLS processing works in the FlexiBee REST API). Now it is necessary to prepare a conversion script that transforms the XML. For this purpose, we use standard XSL Transformations (XSLT).
Conversion from XML to XML (XSLT)
XSL Transformations (XSLT) are a standardized tool. However, implementation differences sometimes occur, which is why we provide the Flexi2XML tool, which is built on the same core as Flexi. This ensures maximum compatibility.
Let's prepare a conversion script (odberatel-in.xslt):
<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xalan/java" version="1.0" exclude-result-prefixes="java"> <xsl:output method="xml" indent="yes" encoding="utf-8"/> <xsl:template match="/winstrom"> <winstrom version="1.0"> <xsl:apply-templates select="odberatel"/> </winstrom> </xsl:template> <xsl:template match="odberatel"> <odberatel> <firma>code:<xsl:value-of select="java:flexibee.Tool.toUpper(Odběratel)"/></firma> <cenik>code:<xsl:value-of select="java:flexibee.Tool.toUpper(Ceník)"/></cenik> <prodejCena> <xsl:value-of select="Cena"/> </prodejCena> </odberatel> </xsl:template></xsl:stylesheet>
In XSLT it is possible to iterate (<xsl:for-each/>), use conditionals (<xsl:if/>), and index content (<xsl:key/>). However, this is not classical iterative programming. We are aware that XSLT has its limitations, but for these purposes it appears to be the ideal choice.
Then use the following command:
flexibee2xml --from-xml soubor.xml --run-xslt odberatel-in.xslt --to-xml vysledek.xml
Or as a single command, skipping the intermediate step:
flexibee2xml --from-xls soubor.xls --evidence odberatel --run-xslt odberatel-in.xslt --to-xml vysledek.xml
The resulting output can then be imported into Flexi either directly or via batch processing with Flexi2XML.
A Few Closing Notes
The resulting XSLT transformation can be saved as a User Transformation or integrated directly into Flexi (you need to send it to us by email). This allows Flexi to easily produce or consume XML from other systems. The use of a user-defined (or integrated) XSLT transformation is described in the REST API documentation.
Multiple files can be processed at once — this is useful when you have one CSV/XLS file with invoice headers and another with line items.
Flexi2XML can also be used to split a large XML file into many smaller ones and upload them sequentially.
