So I take it this is something you do regularly, not something that needs to get done once? if it were a oneshot operation it would be simpler to use TextWrangler.
For repeated use, the simplest approach is to run through the files and apply text item delimiters to each tag:
set indesignTags to {"idtag1", "idtag2", "idtag3"}
set htmlEquivs to {"htmltag1", "htmltag2", "htmltag3"}
set theFiles to choose filewith prompt "Choose indesign files" with multiple selections allowed
repeat with aFile in theFiles
-- get file text
set fileText to readaFile
-- swap tags
repeat with i from 1 to count of indesignTags
-- swap lead tags
set fileTextBits to tid({input:fileText, delim:"<" & itemi of indesignTags})
set fileText to tid({input:fileTextBits, delim:"<" & itemi of htmlEquivs})
-- swap trailing tags
set fileTextBits to tid({input:fileText, delim:"</" & itemi of indesignTags})
set fileText to tid({input:fileTextBits, delim:"</" & itemi of htmlEquivs})
end repeat
-- make new file path with html extension
set oldFilePath to POSIX path of aFile
set filePathBits to tid({input:oldFilePath, delim:"."})
set last item of fileNameBits to "html"
set newFilePath to tid({input:filePathBits, delim:"."})
-- save at new file path
set fp to open for accessnewFilePath with write permission
writefileTexttofp
close accessfp
end repeat
on tid({input:input, delim:delim})
-- handler for text items
set {oldTID, my text item delimiters} to {my text item delimiters, delim}
if class of input is list then
set output to input as text
else
set output to text items of input
end if
set my text item delimiters to oldTID
return output
end tid
This will work if the indesign tags are unique and there is no complex syntax. It might fail if tags have overlapping names (e.g. "<bl>" and "<blue>") or if there's any irregular notation. If you need more sophisticated handling you'll have to use regular expressions. In that case, download and install the Satimage osax from this page, and use the following (similar) code:
set indesignTags to {"idtag1", "idtag2", "idtag3"}
set htmlEquivs to {"htmltag1", "htmltag2", "htmltag3"}
-- set up regular expressions change lists
set findList to {}
set changeList to {}
repeat with i from 1 to count of indesignTags
set end of findList to "(</?)" & item i of indesignTags & "(?![[:alnum:]])"
set end of changeList to "\\1" & item i of htmlEquivs
end repeat
set theFiles to choose filewith prompt "Choose indesign files" with multiple selections allowed
repeat with aFile in theFiles
-- get file text
set fileText to readaFile
-- swap tags - needs Satimage osax
set fileText to changefindListintochangeListinfileText with regexp
-- make new file path with html extension - needs Satimage osax
set oldFilePath to POSIX path of aFile
set newFilePath to change "\\.[^.]+$" into ".html" in oldFilePath with regexp
-- save at new file path
set fp to open for accessnewFilePath with write permission
writefileTexttofp
close accessfp
end repeat
Message was edited by: twtwtw - I made an error in the second regular expression. should be "\\.[^.]+$", not "\\..*$". fixed in text.