Arbortext Command Language > Using the Arbortext Command Language > Example: Substituting Tags
  
Example: Substituting Tags
Currently, you cannot use the substitute command to insert, delete, or change tags. The following series of commands (which would be put in a file and called with the source command) gets around this restriction by interactively inserting a tag pair around every occurrence of the phrase selected. By substituting change_tag or delete_tag for insert_tag in the command sequence that follows, you could design a similar procedure which would delete or change tags in the highlighted phrase.
set sgmlselection=off
$phrase=$selection
set sgmlselection=on wrapscan=off
if ($tagname != "") {
if (substr($tagname,1,1) == '/') {
$TAG=substr($tagname,2,length($tagname)-1);
}
else {
$TAG=$tagname
}
} else {
$TAG='NO_TAGS'
}
if ( "$TAG" == "NO_TAGS" ) {
message "No tags allowed in ascii file"
} else if ("$phrase" && "$TAG") {
find -sel "$phrase";
while ($status == 0) {
$ack=response("Change?", "Yes", "No", "Cancel")
if ($status != 0 || $ack == 3) { break;}
if ($ack == 1) {
break;
}
if ($ack == 1) {
insert_tag $TAG}
}
find
}
} else {
message "You must select something first"
}
unsetvar TAG phrase
For example, if you want to put emphasis tags around almost every occurrence of “Arbortext Editor” in your document, find the first occurrence of the phrase in your document and put emphasis tags around it. Then select the entire phrase (including the emphasis tags) and source the file containing the commands listed above. Arbortext Editor then finds each occurrence of the phrase and prompts you to insert the tag pair. To insert the tag, click on the Yes button on the prompt panel. To skip the phrase (for example, if the occurrence were already tagged), click on the No button. To get out of the search-and-tag operation (abort the loop), click on the Cancel button.
This command script could also be written as a user-defined function.