Count value in XML

I’m looking to make a counter that counts instances of a specific value of a field.

You need to give more detailed information on what exactly you want to do.

if it is a simple record field you could loop over record in an Action Step Javascript, add a counter variable in the loop and increase that counter every time your field value is encountered.

Pseudocode, not tested:

let counter = 0;
let len = record.length();
for (i=0;i<len;i++) {
  if (record[i].field == "foo") counter++;
}

The more effective way would be to use XPATH’s count() function.

For example, with the following data file,


you would use

  ./CUSTOMER[1]/INVOICES[1]/INVOICE[1]/count(ITEM[BackOrder=0])

to get a count of all BackOrder fields that have a value of 0.

Similarly, with the proper syntax, you can get a count of all items that are greater/less/different than any value you like:

  ./CUSTOMER[1]/INVOICES[1]/INVOICE[1]/count(ITEM[BackOrder>0])
  ./CUSTOMER[1]/INVOICES[1]/INVOICE[1]/count(ITEM[BackOrder<0])
  ./CUSTOMER[1]/INVOICES[1]/INVOICE[1]/count(ITEM[BackOrder!=0])