Table of Contents

Search

  1. Preface
  2. Introduction to Data Transformation
  3. Data Processor Transformation
  4. Wizard Input and Output Formats
  5. Relational Input and Output
  6. XMap
  7. Libraries
  8. Schema Object
  9. Command Line Interface
  10. Scripts
  11. Parsers
  12. Script Ports
  13. Document Processors
  14. Formats
  15. Data Holders
  16. Anchors
  17. Transformers
  18. Actions
  19. Serializers
  20. Mappers
  21. Locators, Keys, and Indexing
  22. Streamers
  23. Validators, Notifications, and Failure Handling
  24. Validation Rules
  25. Custom Script Components

Data Transformation User Guide

Data Transformation User Guide

XPath Expressions Example

XPath Expressions Example

Use XPath expressions in mapping statements. XPath expressions identify the elements in the input document to be mapped and transformed in the output document. An XPath expression is also used to perform an arithmetic operation.
The following figure shows XPath expressions in the grid:
The XMap editor grid contains mapping statements with XPath expressions in the Input and Output fields. In the Input field, an XPath expression provides the context for the mapping statement. In an Output field, the XPath expression defines the output element.
The XMap input document is a list of children and their hobbies. The input root is Children. Child is a multiple-occurring element within Children. Each child has a Name and multiple-occurring hobbies. Name consists of First, Initial, and Last elements.
The output is a list of the classes with the number of children in each class. The output root is Classes. Classes has an attribute that contains the total number of classes. Each input Hobby element maps to a output Class element. A Map statement concatenates the First, Initial, and Last elements into the Child output element. Another Map statement counts the number of chldren in each class. Another statement counts the number of classes.
The XMap contains the following expressions:
Grid row 2 expression <Class[@name = dp:input()]>
Adds a Class element or find a Class that matches Hobby. The dp:input() is required because the expression refers to an input element.
Grid row 3 expression <concat(../Name/First,' ',../Name/Initial,' ',../Name/Last)>
Concatenates the first name, middle initial, and last name and adds spaces between them.
Grid row 4 expression <dp:output()/@noOfChildren + 1>
For each Hobby that occurs, add 1 to the number of children for that class. The dp:output() function is required because the expression refers to an output element.
Grid row 5 expression <count(dp:output()/Class)>
Counts the Class elements. The dp:output() function is required because the expression refers to an output element.