I am trying to use the some what same logic that is used in here https://stackoverflow.com/a/10629806/662877
to a different XML but not getting the intended output.
The problem is here:
*[../TERR='KHM6']/CreatePaymentItems
This matches the CreatePaymentItems child of an element that has a sibling TERR with value "KHM6".
But all siblings of TERR in the provided XML document are child-less.
Here is the transformation you want:
when applied on the provided XML document (corrected to be well-formed):
4
R2293416
3335889530
05/03/2012
4NZ3330000010
599.99
599.99
1
43.65
1
KHM6
4
R2293416
2293416
TOTM
4
R2293416
05/03/2012
645.03
2293416
4
R2293416
61261585
the wanted, correct result is produced:
4
R2293416
3335889530
05/03/2012
4NZ3330000010
599.99
599.99
1
43.65
1
KHM6
4
R2293416
2293416