A new transform can be created using the File->New menu, and selecting the Data Mapper icon.
When constructing a Data Transformation it's often easier to start with the output component and work back.
The XML output component can be found in the Component Palette (If it's not visible it can be displayed by selecting it in the View Menu"), and can be added to the data mapper canvas by dragging it on.
The XML Data Target loads its meta data (i.e. a description of the output document) from an XML Schema (XSD). If you don't have an XSD then it's possible to infer one from one or more sample XML files which represent the output data you are trying to create. You could also create or modify a schema using the built in XSD Editor.
When XML Data Target is dropped on the data mapper canvas it starts a wizard which will capture all the data required to configure the new XML Data Target, we will use the Bookstore.xsd sample located in C:\Program Files\Liquid Technologies\Liquid XML Studio 2018\Examples\BookStore, the output file will be written to C:\Program Files\Liquid Technologies\Liquid XML Studio 2018\Examples\BookStore\HorrorBooks.xml.
Once you have completed the wizard you will see the new component on the canvas. You will notice its inputs are taken from the structure of the XSD schema you provided as an input.
Now we can think about where to get our input data from. The XML Data Source component will allow us to read data from an XML file. Again we can create one by dragging an XML Data Source from the Component Palette. The XML Data Source component also gets its meta data (i.e. a description of the input document) from an XML Schema (or can be inferred from XML documents). Again we will use the Bookstore.xsd in this example. The reader also needs an input data file, we will use C:\Program Files\Liquid Technologies\Liquid XML Studio 2011\Examples\BookStore\BookStoreSample.xml.
To start with we can connect all the input and output connection points together, this will mirror the input data in the output (not much of a transform, be we can see how things work).
Pressing Shift-F5 () will execute the transform and display the results.
Pressing F5 () will start the debugger, we can then step through the transform seeing the way the transform is executed and watching the data move around. This gives some incite into how the transformation engine works, and understanding unexpected results easier to get to grips with.
Now we can look at making the transform do something useful, we will apply a simple filter to the data, only selecting books in the "Horror" genre.
Drag a Filter onto the canvas (in the "Set" section) and connect its "Nodes" input to the "book" output, this gives the Filter its context, i.e. it's operating within the context of each book. Connect the Filters "Result" output back to the "book" input connection point on the output component. If the Filters "bool" input receives a true value then the current book object will be output via the "Result", otherwise it's discarded.
Drag on an Equals component (in the Equality section) and connect its "result" to the filters "bool" input. Connect one of its inputs to the XML Sources "genre" output.
Drag on a Constant component (in the Constant section) set its type to be String and its value to be Horror (right click on it and select "Properties"). Connect its "Value" connector to the other input on the Equals component.
When we run the transform it now filters the input books only returning ones that contain a genre which equals "Horror".
The transform output |
Copy Code
|
---|---|
<bookstore xmlns="https://www.liquid-technologies.com/sample/bookstore"> <book price="4.99" publicationdate="2008-10-20T00:00:00Z" ISBN="978-0747596837"> <title>The Graveyard Book</title> <author> <first-name>Neil</first-name> <last-name>Gaiman</last-name> </author> <genre>Horror</genre> </book> </bookstore> |
Let's look at what we have created, and how it runs. First off start the debugger (F5 ) and step through the transform (F-11 ) you'll notice that things run from right to left. Values are requested from a component, which triggers the component to pull values from its child inputs.