XSLT3 adds trigonometry and other advanced math functions, new formatting functions, functions to collect environment variables, and more, extending XSLT and XSLT2 XML transformation standards. Data analysts and other data professionals can apply XSLT3 functions to solve XML data mapping and integration challenges that require complex mathematical computations. Let’s look at some MapForce examples of data mapping with XSLT3 math functions using trigonometry and other complex math expressions.
MapForce offers internal processing engines customized for various data types and applications.
When you choose the XSLT3 engine the functions shown below are added to the Function Library window and are available for data mapping:
For example, we can create a data mapping that generates sine, cosine, and tangent for input values stored in an XML file. The original list came as a CSV file we imported into XMLSpy, the world’s best-selling JSON and XML editor, for conversion to XML.
We start the mapping in MapForce by dropping in XML Schemas for the input and output files, then connecting the root elements. At this point it’s important to select the standard target-driven connection type. This lets us customize each subsequent connection.
Next, we connect the Row elements, drag in the trig functions from the library, and connect the xvalue element from the source to each function and output element. Here is the completed data mapping:
Clicking the Output button below the mapping pane processes the input file, generates the output, and opens the preview window.
The input values in this example count from zero to 15 by tenths and the output contains each corresponding sine, cosine, and tangent. We can save the file and open it in XMLSpy, to take advantage of XMLSpy Grid view, create a highly customized graph, and even export the graph to include in a report or presentation:
Data Mapping with XSLT3 to Build Complex Expressions
You can combine XSLT3 functions with other functions in the library to build complex expressions. Let’s say we want to apply a quadratic equation like y = 4x2 – 3 to a list of input values. We can create a mapping that combines the XSLT3 pow function for the exponent with the core library functions for multiplication and addition.
Note the sequence of functions in the mapping explicitly defines the processing order implied in the expression: exponent first, then multiplication, then subtraction. If the expression used parentheses to override the default processing order, we would change the sequence of functions in the mapping to set the desired processing order.
Perhaps we want to run a set of input values through several variations of the expression and compare the results. We can create a user function to describe the expression and we can modify the structure of the output file to record the exponent, multiplier, and modifier used to generate each output file.
Here is the desired structure for each output file generated by variations of the expression:
The user function will accept x values from the input XML file, calculate the expression, and will also pass the function parameters to be recorded in the output.
Here is the complete mapping with the expression in a user function:
And the generated output file:
A user function can be easily inserted into other mappings or shared among multiple MapForce users. We start building a user function by selecting the functions that define the expression, then click the main Function menu:
Here is our final definition of the user function:
If your data mapping and integration project requires data mapping with XSLT3 fortrigonometry or other advanced XSLT3 functions, check out MapForce, the award-winning, graphical data mapping tool for any-to-any data conversion and integration. Download a MapForce free trial including Tutorials, Help, and many more examples!