Skip to main content
1-Visitor
October 13, 2015
Solved

What ACL command(s) can I use to modify a table after insert it using tbl_insert() command?

  • October 13, 2015
  • 2 replies
  • 5545 views

Hello gurus!

So I'm tying to modify a Table that I inserted using tbl_insert() acl command, working in a DITA Topic file and using the Insert>Table>OASIS Exchange... option from the Arbortext Editor Menu; what I want to do is to add a new row at the end of the table and also insert the tags <title/> and <desc/> as a predefined format for the selected table.

Does anybody knows how can I achieve this? I've been looking up in the ACL guide but I haven't found something clear. Please help me!

In advance I appreciate your time and help.

Paulette Z.

    Best answer by ClayHelberg

    Hi Paulette--

    Probably the easiest thing is to find the <tbody> element, and insert your new row at the end of that. Here is a simple function that does this (assuming the caret is already somewhere inside the table body):

    function addRow() {

      local oid = oid_caret();

      while (oid_valid(oid) && (oid_name(oid)!="tbody")) {

        oid = oid_parent(oid);

      }

      if (!oid_valid(oid)) {

        response("Try again with the caret inside a table");

        return;

      }

      goto_oid(oid,-1);

      insert("<row><entry/><entry/></row>");

    }

    HTH

    --Clay

    2 replies

    18-Opal
    October 13, 2015

    Hi Paulette--

    For the title, you should be able to use tbl_table_title_insert(), and for the extra row you can use tbl_obj_add(). If you want these to happen automatically, take a look at the tbl_insert doc callback (look up doc_add_callback() in the online help).

    For the <desc>, I don't think there's a custom table function for that, so you will probably just need to start from the table wrapper element and use the standard insert() function or insert_tag command.

    --Clay

    pzorrilla1-VisitorAuthor
    1-Visitor
    October 14, 2015

    Clay, I've been testing the tbl_obj_add() command and the tbl_table_title_insert() command; from both of them I received a response telling me that those operations are not allowed on the corresponding type  of table So I was wondering, do you know if there's any way to obtain the rows from a table and modify them by separate?

    I really appreciate your time and your quick response on my previous post.

    Have a nice day!

    Paulette

    18-Opal
    October 15, 2015

    Well, on closer inspection, it seems the OASIS (CALS) table model doesn't support inserting a table title using tbl_table_title_insert(). (The documentation mentions this, but I overlooked it earlier.) Maybe this is because a DITA table can have a wrapper (<simpletable>) that doesn't support the <title> element.

    Anyway, it looks like you may have to use a direct DOM table structure approach to this problem. For the <title> and <desc>, find the container <table> element and use the usual insert_tag command or insert() function. For example, to insert a new element into a table (at the wrapper level), something like this should work (where the caret is inside the table:

    function add_table_element(name, text) {

         local oid = oid_caret();

         while (oid_valid(oid) && (oid_name(oid) != "table")) {

              oid = oid_parent(oid);

         }

         goto_oid(oid);

         insert("<" . name . ">" . text . "</" . name . ">");

    }

    You would need to add some error checking (if caret is not inside table, if the requested element already exists, etc.), and make sure you add the elements in the right order to make sure the result is valid.

    I was able to get row insertion to work in a DITA document using code like this (where the caret is anywhere in the table to be updated):

    function add_row() {

      local toid = tbl_oid_cell(oid_caret());

      local tgrid = tbl_obj_grid(toid);

      local rows[];

      local nrows = tbl_grid_rowlist(tgrid, rows);

      tbl_obj_add(rows[nrows], 0);

    }

    Of course, you can always find the <tgroup> element and insert your own <row> element as described above. If you take that route, you'll also need to insert the correct number of <entry> elements to keep the table structure intact.

    --Clay

    12-Amethyst
    October 22, 2015

    Did Clay's instructions allow you to resolve your issue?

    Did you have to make additional modifications? If so, could you describe them?

    pzorrilla1-VisitorAuthor
    1-Visitor
    October 26, 2015

    Tim, than you for asking..

    Clay's help was very useful, he don't just gave me ideas about how to solve it but code, which I appreciate a lot, I'm still having a small issue about what I'm trying to achieve, but it depends more on testing from my part, so thank you!