Scenario:
In some cases, your input data may contain multiple records having the same key field (for example, PARTY_ID). The requirement is to select only the record with the maximum value in another field (for example, VDATETIME) and use a corresponding field (like ADDRESS_SOURCE) for mapping to the target.
Requirement:
For each key (e.g., PARTY_ID), pick the record with the highest (latest) value in another field (e.g., VDATETIME) and map the desired field (e.g., ADDRESS_SOURCE) into the target field (e.g., ADDRESS_DESTINATION).
Note:
The field names used below —PARTY_ID,ADDRESS_SOURCE,VDATETIME, andADDRESS_DESTINATION— are for illustration only.
You can replace them with actual field names as per your mapping requirement.
Example Input File
| PARTY_ID | ADDRESS_SOURCE | VDATETIME |
|---|---|---|
| A3001 | 12 Elm Street | 20240110 |
| A3004 | 45 Pine Avenue | 20240105 |
| A3004 | 99 Oak Drive | 20240320 |
Expected Output File
| PARTY_ID | ADDRESS_DESTINATION |
|---|---|
| A3001 | 12 Elm Street |
| A3004 | 99 Oak Drive |
XPath Expression (Textual Rule Example):
/Root/Record[KeyField = current()/KeyField][CompareField = max(/Root/Record[KeyField = current()/KeyField]/CompareField)]/ValueFieldReplace as per your fields:
| Placeholder | Example Field | Description |
|---|---|---|
KeyField | PARTY_ID | Field used to group records |
CompareField | VDATETIME | Field used to find the maximum value |
ValueField | ADDRESS_SOURCE | Field value to be mapped to the target |
Example Using Actual Fields:
/Root/Record[PARTY_ID = current()/PARTY_ID][VDATETIME = max(/Root/Record[PARTY_ID = current()/PARTY_ID]/VDATETIME)]/ADDRESS_SOURCEExplanation:
current()/KeyField→ Refers to the key value of the current record./Root/Record[KeyField = current()/KeyField]→ Selects all records sharing the same key.[CompareField = max(...)]→ Chooses the record having the maximum comparison field value./ValueField→ Returns the field value from that selected record.
Result:
This XPath ensures that:
For each group of records (same key), only the record with the maximum comparison field value is selected.
- The desired field value from that record is mapped into the target output.
Comments
0 comments
Please sign in to leave a comment.