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

Example: Using dt:next-sequence()

Example: Using dt:next-sequence()

You can use the dt:next-sequence() function to access logically hierarchical data that is not nested within the current element.
Consider the following input:
<Root> <A/> <B/> <C/> <A/> </Root>
The XPath
/Root/A/dt:next-sequence()
returns the following node-set:
<A/> <B/> <C/>
In the following example, each
id
element is associated with a set of sibling elements called
name
,
quantity
, and
price
:
<items> <id>100</id> <name>Plate</name> <quantity>4</quantity> <price>10</price> <id>101</id> <name>Toaster</name> <quantity>6</quantity> <price>10</price> <id>102</id> <name>Knife</name> <quantity>10</quantity> <price>5</price> </items>
The
name
,
quantity
, and
price
elements are all logically nested within
id
, even though they are not nested physically.
The following rule requires that
price*quantity
for each
id
be less than or equal to 50:
<rule code="sum1" select="/items/id" description="For each id, check that the total price (price*quantity) does not exceed 50"> <variable name="current">dt:next-sequence()</variable> <variable name="total">$current[3]*$current[4]</variable> <assert additionalData="$total"><![CDATA[ $total <= 50 ]]></assert> </rule>
For the first
id
element, the variable
$current
is a node-set with the following value:
<id>100</id> <name>Plate</name> <quantity>4</quantity> <price>10</price>
The expression
$current[3]*$current[4}
evaluates to 4*10 = 40. The rule confirms that 40 < 50.
For the subsequent
id
elements, the rule evaluates the expression in a similar way.