Transform Messages Between Versions of LIXI2
With each LIXI2 release we produce XSLT documents to transform LIXI2 XML messages to and from the latest version of each LIXI2 Standard. The transformations are available for every LIXI2 release from the Master Schema 2.0.0 until the most recent release. You can download the XSLT sheets from the LIXILab XSLT Project.
In addition to this, we have created a tool that simplifies the process of transforming LIXI2 messages. The tool is available as a feature of the LIXI Python Package. Not only can the transformation tool transform XML messages, it can also transform JSON messages between LIXI2 versions.
The three steps you should follow to transform a message between versions of LIXI2:
Read a LIXI2 Message using the LIXI Python Package
1) Install the LIXI Python Package
Before you can access the LIXI python package in your Python code, you must install the package with this command:
pip install lixi
2) Download the LIXI2 schema for your LIXI2 message
To read a LIXI2 message using the LIXI Python package, you will need the appropriate schema file corresponding to the version of your LIXI2 message. Links to download LIXI2 schemas can be found here: LIXI standards Release History.
3) Import the LIXI package into your Python script
Add this import statement to your code to import the LIXI package into your script:
4) Read your LIXI message using the LIXI Python Package
Sample LIXI2 messages for Single Applicant Credit Application or Joint Applicant Credit Application are available on our Credit Application Tutorials (available to logged in members). Read your LIXI2 message using the following code (being sure to use the correct file paths for your LIXI2 message and LIXI2 schema).
lixi_message = lixi.read_message( message_path="message.xml", schema_path="LIXI-CAL-2_6_22-Annotated.xsd" )
You can query your LIXI message object to find out the LIXI2 version of the message with this command:
Get Transformation Warnings before Executing a Transformation
Before you execute the version transformation, you should review the transformation warnings. The warnings provide detailed information on any data that will be lost in the transformation.
The warnings will specify:
- All data values that will be removed, updated, or appended in the transformation
- The location in the message of the data that will be removed, updated, or appended
- The reason the data will be removed, updated, or appended in the desired LIXI2 version
Execute this code to get the warnings:
warnings = lixi_message.get_transform_warnings( to_version="2.6.19", output_path="warnings.xml" )
And print to display the warnings to the terminal:
Each warning will look something like this:
<removed name="Category" path="/Package/Content/LivingExpense/Category" reason="enumeration not available" type="attribute" value="Investment Property Running Costs"/>
The warning sheet provides sufficient information to reconstruct the original message.
Transform a LIXI2 message between versions of LIXI2
Now that we have our LIXI message object (and we have checked the warnings for any data that will be lost in the transformation) we can transform it to the desired version using the transform_message function.
The LIXI message object will be transformed in place, so that if we were to print the object to the terminal using the pretty_print function we would see the LIXI2 message in the transformed version.
Likewise, if we were to save the message to file using the save function, the file would be in the transformed version.
Learn to transform a LIXI2 messages from XML to JSON (or from JSON to XML): Convert a LIXI2 message from XML to JSON.
An introduction to the LIXI Python Package: Introducing the LIXI Python Package.
The detailed package documentation for the LIXI Python Package includes a Quickstart Guide that takes you through all the key functionality (available to logged in users - any member or licensee can register for a free account here).
Finally, feel free to contact any member of the LIXI team (or use our contact form) and we will be happy to help with more information.
John Matthews, LIXI Technical Lead
First Published: March 16, 2020