Exercise 5.5 – Functions
Purpose:
To practice using XSLT functions in the Data Mapper.
References:
Create a Route
- From the eiConsole File Management screen, select the Add Route button.
- In the dialog that appears, enter the name Functions and select OK.
- The Route should now appear in the table on the screen. Double-click it to open it.
Document Source System
- Select the Source System stage in the Route Editing Grid. The configuration panel will appear at the bottom.
- Change the System Name to People XML File.
- Select the Choose Source Icon button, and scroll down to select one of the XML icons.
Configure the Listener
- Select the Listener stage in the Route Editing Grid. The configuration panel will appear at the bottom.
- Select Directory/File from the Listener Type selection box. Optionally, click the … button to open the Module Search Dialog, which provides a faster way to find the module you’re looking for.
- Assign a polling directory using the … button to open the file selector. The polling directory should NOT be the directory with all the sample files, since files will be moved/deleted by the listening process.
- Go to the Post-Process tab and select Delete from Postprocess Operation.
Add Source Format and Open Data Mapper
- Select the Source Transform stage in the Route Editing Grid. The configuration panel will appear at the bottom.
- Click the Add Format button. In the dialog that appears, name the Format People to Robots 3, and click OK. The transformation configuration panel will appear below.
- On the right-hand side, in the XSLT To XML configuration panel, uncheck the Use Direct Relay button. The options in that panel will now be enabled.
- Click the New button beneath the checkbox to open the Data Mapper.
Load Source and Target Formats
- Use the Open Source Format button above the Source Format panel to open the Select Format dialog. Choose XML from the Format Reader selection box.
- Click the Add button, and in the File Selector navigate to where the sample files are located. Choose the file called people.xml. Click OK, and then click Read Format.
- Use the Open Target Format button above the Target Format panel to re-open the dialog. From the XML Format Reader, re-open the File Selector and select the file called robots.xml. Click OK, and then click Read Format.
- The Source and Target format panels should now be populated.
Map the Root Nodes and Add Iteration
- Select the People Node that is the root of the tree in the Source panel to the left. Drag it onto the center panel, and drop it on the stylesheet node that’s already there.
- Select the Robots node that is the root of the tree in the Target panel to the right. Drag it onto the center panel, and drop it on the People node that was just dropped there. This creates the implicit default Template in the XSLT document.
- Above the center mapping panel is the extensions panel. The currently displayed tab, Filter by Pattern, has a text field called Pattern. Type for-each into that field.
- A single item should be present in the panel. This item should also be called for-each. Select it and drag it onto the Robots node in the center mapping panel.
- Select the Person node that is a child of the People node in the Source format tree, and drag it onto the @select node beneath the for-each node in the center mapping panel.
- Select the Robot node that is a child of the Robots node in the Target format tree, and drag it onto the for-each node in the center mapping panel.
Finish the Mapping
- Select all of the Nodes that are children of the Robot node in the Target format panel, and drag them onto the center panel and drop them onto the Robot node.
- Click the + button next to the Title, Vehicle, and Location nodes in the Target format panel to expand them to show their child nodes.
- Select all the child nodes beneath Vehicle in the Target format panel, and drag them onto the center panel and drop them onto the Vehicle node there. Repeat this with the children of Location.
- Now that the whole Target format has been configured in the center panel, it’s time to map the Source format to it. Map the nodes in the following way:
- Source: Gender -> Target: Type
- Source: SSN -> Target: ID
- Source: BirthDate -> Target: CreationDate
- Source: Occupation -> Target: Function
- Source: Vehicle/Make -> Target: Vehicle/Make
- Source: Vehicle/Model -> Target: Vehicle/Model
- Source: Vehicle/Year -> Target: Vehicle/Year
- Source: Address/Line1 -> Target: Address/Line1
- Source: Address/City -> Target: Address/City
- Source: Address/State -> Target: Address/State
- Source: Address/Zip -> Target: Address/Zip
- The target Title node in the center mapping panel has been deliberately left without any children at this point.
Add Concat Function
- Find the Title Target element in the center mapping panel.
- In the top extensions panel, type concat into the Filter by Pattern field. The concat item will appear below. NOTE: if two concat items appear, use the one without parenthesis.
- Drag the concat item out of the extensions panel and onto the center mapping panel and drop it on the Title Target node.
- The Concat dialog will appear so you can set a custom number of items to concatenate. Choose 3 and click OK.
- The concat node will now be a child of the Title node in the mapping. Beneath it is a node called @select with a plus-sign bubble next to it. Click the plus-sign bubble to expand the node so that its three value children are visible.
- From the Source tree to the left, drag Name/First onto the first value node, Name/Middle onto the second value node, and Name/Last onto the third value node.
- This will concatenate the values without any spaces in between them.
- Now that the mapping is complete, click the Save icon in the toolbar above the tree. When prompted for a name, use the default, transform.
- Click the X button in the top right corner to close the Data Mapper and return to the Route Editing Grid.
Configure the Transport
- Select the Transport stage in the Route Editing Grid. The configuration panel will appear at the bottom.
- Select Directory/File from the Transport Type selection box. Optionally, click the … button to open the Module Search Dialog, which provides a faster way to find the module you’re looking for.
- Select the Target Directory using the … button to open the file selector.
- Set robots-function-output as the Target File Name.
- Set xml as the Target File Extension.
Document the Target System
- Select the Target System stage in the Route Editing Grid. The configuration panel will appear at the bottom.
- Change the System Name to Robots XML File.
- Select the Choose Target Icon button, and scroll down to select one of the XML icons.
Prepare to Test
- In the menu bar at the top, select Mode -> Testing Mode. Make sure the changes to the Route are saved.
- Copy the file called people.xml from the Samples directory provided into the directory chosen as the polling directory.
Perform the Test
- At the top of the Testing Mode screen, select the Execute Test button.
- If the Route was configured successfully, all the Stages should light up with green checkmarks.
- In the OS File Explorer, open the directory selected as the Target Directory. The file robots-function-output.xml should be there, with the transformed contents produced by the XSLT.
Output Files
- Compare the results from the exercise with the following example output files to see if they are correct.