Question
useful ACL script
As I slowly start thinking about 'retiring' (and I'll think VERY SLOWLY on
that), I think I'll pass on some of the little scripts I've put together
over the years.
This one I did a couple of months ago before I delivered a large (1,400
page) document. It will go through and tell you if there are any elements
that normally would have content but are empty. There are two functions in
this package. One will allow you to select a specific element to see if
there are any empty tags, the other will check all the elements in the
document.
I documented the first function and only those changes in the second
function that differ from the first.
How I chose to implement this is shown after the script.
package empty_elements;
function empty_element(){};
function empty_element1(){};
function empty_element()
{
o=oid_first(); #sets the 'o' variable to the first oid in the file
cl=oid_caret() #identifies the current location of the cursor in the
document
count=0; #This will count the number of elements that are empty
count1=0; This counts all the elements that are evaluated.
eval " #this clears any previous text in an 'eval' output.
#the two 'readvars' prompt you to decide if you want to show the context
(where in the file you approximately are
#and for you to enter the name of the element you want to search for. This
line IS NOT used in the second function.
readvar -prompt "Do you want to show empty element context? "\
-choice "Yes|No" choice;
readvar -prompt "Enter tag name: " name
# the 'while' sets the limit on how long to search. Only while there is a
valid OID.
while (oid_valid(o));
{
$name1=oid_name(o); # this assigns a variable name to the name of each
OID.
# the 'if' statement compares the current oid name to that of the element
you are checking
if(oid_name(o)=="$name")
#this if ensures the element is in the DTD or schema.
{if(oid_declared_tag($name)=="1")
{ count1++
#This 'if' skips over elements that are declared "EMPTY" in the DTD or
schema and passes those have nothing
#in their content model.
#The counter for the empty elements is incremented AND if you chose to see
the context of where the empty
#element is located, the cursor is moved to that oid and the context string
read into a variable.
# Lastly, either the element name and context string or just the element
name is added to an output window.
if(oid_empty(o)=="1" && oid_content_model(o)!=")
{
count++;
if ($choice=="Yes");
{goto_oid(o);
cm=context_string()
eval "$count. $name1 has no content. Context is $cm"
output=>*
}
else
{eval "$count. $name1 has no content." output=>*}
}
}
}
#This moves the oid variable forward through the file
o=oid_forward(o) ;
}
#At the end of the 'while' this 'if' statement will tell you if there are NO
empty elements of the name you
#searched.
if(count=="0")
{eval "There are no $name elements with no content."}
#This statement tells you the number of number of the searched element are
in the file. Just FYI, but nice to
#know you actually searched something.
eval "Total number of $name elements $count1" output=>*
#This returns the cursor to where you were originally in your document.
goto_oid(cl)
}
function empty_element1()
{
o=oid_first();
cl=oid_caret()
count=0
count1=0
eval "
readvar -prompt "Do you want to show empty element context? "\
-choice "Yes|No" choice;
#readvar -prompt "Enter tag name: " name "the tag name is not needed here,
we are checking all elements.
while (oid_valid(o));
{
$name1=oid_name(o);
# if(oid_name(o)=="$name") again, removed the specific name search.
{if(oid_declared_tag(oid_name(o))=="1")
{ count1++
if(oid_empty(o)=="1" && oid_content_model(o)!=")
{
count++
if ($choice=="Yes");
{goto_oid(o);
cm=context_string()
eval "$count. $name1 has no content. Context is $cm"
output=>*
}
else
{eval "$count. $name1 has no content." output=>*}
}
}
}
o=oid_forward(o) ;
}
if(count=="0")
{eval "There are no $name elements with no content."}
eval "Total number of elements $count1" output=>*
goto_oid(cl)
}
First you will need to 'source' the script in some opening configuration.
Once the file is sourced, it remains available as long as the Epic session
is open. The next two commands I have in a third script that invokes
numerous menu changes. The two lines here will add this to the right click
popup menu. NOTE, this will not work inside a table as Epic automatically
changes the popup when the cursor is inside a table. You can add these to
the above script or in a separate file if you have numerous menu
modifications (I have around 50 between the main menu where I add two new
items and popup additions).
mad :EditPopup 'Empty tag-specific' -cmd {empty_elements::empty_element()};
mad :EditPopup 'Empty tags-any' -cmd {empty_elements::empty_element1()};
I found this to be handy when I found a numbered paragraph in my document
with nothing in it. It is certainly easier than manually going through a
document with over 75,000 elements that are expected to have content.
Authors may not need this, but an editor or QA might find it beneficial.
If you think this or some other scripts along these lines might be helpful,
let me know and I'll post some of my other ones.
Lynn
that), I think I'll pass on some of the little scripts I've put together
over the years.
This one I did a couple of months ago before I delivered a large (1,400
page) document. It will go through and tell you if there are any elements
that normally would have content but are empty. There are two functions in
this package. One will allow you to select a specific element to see if
there are any empty tags, the other will check all the elements in the
document.
I documented the first function and only those changes in the second
function that differ from the first.
How I chose to implement this is shown after the script.
package empty_elements;
function empty_element(){};
function empty_element1(){};
function empty_element()
{
o=oid_first(); #sets the 'o' variable to the first oid in the file
cl=oid_caret() #identifies the current location of the cursor in the
document
count=0; #This will count the number of elements that are empty
count1=0; This counts all the elements that are evaluated.
eval " #this clears any previous text in an 'eval' output.
#the two 'readvars' prompt you to decide if you want to show the context
(where in the file you approximately are
#and for you to enter the name of the element you want to search for. This
line IS NOT used in the second function.
readvar -prompt "Do you want to show empty element context? "\
-choice "Yes|No" choice;
readvar -prompt "Enter tag name: " name
# the 'while' sets the limit on how long to search. Only while there is a
valid OID.
while (oid_valid(o));
{
$name1=oid_name(o); # this assigns a variable name to the name of each
OID.
# the 'if' statement compares the current oid name to that of the element
you are checking
if(oid_name(o)=="$name")
#this if ensures the element is in the DTD or schema.
{if(oid_declared_tag($name)=="1")
{ count1++
#This 'if' skips over elements that are declared "EMPTY" in the DTD or
schema and passes those have nothing
#in their content model.
#The counter for the empty elements is incremented AND if you chose to see
the context of where the empty
#element is located, the cursor is moved to that oid and the context string
read into a variable.
# Lastly, either the element name and context string or just the element
name is added to an output window.
if(oid_empty(o)=="1" && oid_content_model(o)!=")
{
count++;
if ($choice=="Yes");
{goto_oid(o);
cm=context_string()
eval "$count. $name1 has no content. Context is $cm"
output=>*
}
else
{eval "$count. $name1 has no content." output=>*}
}
}
}
#This moves the oid variable forward through the file
o=oid_forward(o) ;
}
#At the end of the 'while' this 'if' statement will tell you if there are NO
empty elements of the name you
#searched.
if(count=="0")
{eval "There are no $name elements with no content."}
#This statement tells you the number of number of the searched element are
in the file. Just FYI, but nice to
#know you actually searched something.
eval "Total number of $name elements $count1" output=>*
#This returns the cursor to where you were originally in your document.
goto_oid(cl)
}
function empty_element1()
{
o=oid_first();
cl=oid_caret()
count=0
count1=0
eval "
readvar -prompt "Do you want to show empty element context? "\
-choice "Yes|No" choice;
#readvar -prompt "Enter tag name: " name "the tag name is not needed here,
we are checking all elements.
while (oid_valid(o));
{
$name1=oid_name(o);
# if(oid_name(o)=="$name") again, removed the specific name search.
{if(oid_declared_tag(oid_name(o))=="1")
{ count1++
if(oid_empty(o)=="1" && oid_content_model(o)!=")
{
count++
if ($choice=="Yes");
{goto_oid(o);
cm=context_string()
eval "$count. $name1 has no content. Context is $cm"
output=>*
}
else
{eval "$count. $name1 has no content." output=>*}
}
}
}
o=oid_forward(o) ;
}
if(count=="0")
{eval "There are no $name elements with no content."}
eval "Total number of elements $count1" output=>*
goto_oid(cl)
}
First you will need to 'source' the script in some opening configuration.
Once the file is sourced, it remains available as long as the Epic session
is open. The next two commands I have in a third script that invokes
numerous menu changes. The two lines here will add this to the right click
popup menu. NOTE, this will not work inside a table as Epic automatically
changes the popup when the cursor is inside a table. You can add these to
the above script or in a separate file if you have numerous menu
modifications (I have around 50 between the main menu where I add two new
items and popup additions).
mad :EditPopup 'Empty tag-specific' -cmd {empty_elements::empty_element()};
mad :EditPopup 'Empty tags-any' -cmd {empty_elements::empty_element1()};
I found this to be handy when I found a numbered paragraph in my document
with nothing in it. It is certainly easier than manually going through a
document with over 75,000 elements that are expected to have content.
Authors may not need this, but an editor or QA might find it beneficial.
If you think this or some other scripts along these lines might be helpful,
let me know and I'll post some of my other ones.
Lynn

