Many thanks, first off, to Dan T for his help.
{Edit by Adam Bell: see this thread for the previous result}
I got the loop working. The idea behind the loop is to have each odd member of an array replace the even member that comes right after them. The final product is supposed to swap characters that XML doesn’t take for their entities, i.e. & for & and so forth.
The loop works fine when the items in the array are things like {“item1”, “item2”, “item3”, “item4”…} The replacements go as planned.
** But when I start adding the array members for the entity swap, the replacement fails to take place. **
To do the replacement, I’m using an old UNIX command called sed. Kinda old, but wicked fast. At some point, we may have to work on hundreds of files at once, so we need fast.
The code follows. It takes the contents of file_a, copies them to hold_file1, then hold_file1 and hold_file2 swap about (sed can’t change it’s input file, only output to another file), then hold_file2 copies itself into end_file.
Best wishes,
Laurel
set test_list to {"&", "&", "¢", "¢", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10"}
set x to 1
set y to 2
do shell script "cp /Users/kschalk/desktop/file_a /Users/kschalk/desktop/hold_file1"
--loop to replace members of an array with other members of an array.
--This loop replaces each even members of the array with the odd member before it.
--This counter number needs to be the same as the number of entity pairs.
repeat while y ≤ (count of items in test_list)
set var1 to item x of test_list as text
set var2 to item y of test_list as text
--setting the item it will be replaced with (entity)
--works on hold_file1 and outputs data to hold_file2
do shell script "sed 's/" & var2 & "/" & var1 & "/g' /Users/kschalk/desktop/hold_file1 > /Users/kschalk/desktop/hold_file2"
--copies hold_file2 to hold_file1
do shell script "cp /Users/kschalk/desktop/hold_file2 /Users/kschalk/desktop/hold_file1"
--increase the counters
set x to x + 2
set y to y + 2
end repeat