cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

ACL script to add desc and sthead to all the tables in the document automatically

celias
1-Newbie

ACL script to add desc and sthead to all the tables in the document automatically

Hi All I'm new in ACL, and I want to insert automatically desc and sthead in the tables at the document, I was thinking to do something like this:

function _addMissingTags(){

    oid = oid_first();

    oid_find_children(oid,$tables,"table");


  for( i = 1; i < count($tables); i++){

         oid_table = $table[i];

         goto_oid( oid_table);

          oid_find_children(oid,$desc,"desc");

           if(count($desc) <  1){

             insert("<desc></desc>");

           }

    }

}

but it is not working, any help?

Thanks!!

1 REPLY 1

Hi Carolina--

You probably have an issue with context. If you are using DITA (or a specialized version of it), the <desc> element has to follow any <title> element in the table. So, if your tables have titles, then you code will try to insert the <desc> at the beginning of the <table>, before the <title>, which is not allowed by the doctype.

There were also a couple of typos:

  • oid_table = $tables[i];
  • for (i = 1; i <= count($tables); i++) {
    • you could also simplify this as: for (i in tables) {

If you add a check for the title, you should be able to make it work. Try something like this:

function _addMissingTags(){

    oid = oid_first();

    oid_find_children(oid,$tables,"table");


  for( i = 1; i <= count($tables); i++){

        oid_table = $tables[i];

        goto_oid( oid_table);

          oid_find_children(oid,$desc,"desc");

          if(count($desc) <  1){

            oid_find_children(oid_table, $desc, "title");

            if (count($desc) > 0) {

                # we found a title, move caret after it

                goto_oid($desc[1],-3); # -3 means "after the oid element";
            }

            insert("<desc></desc>");

          }

    }

}

--Clay

Top Tags