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

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

SOLVED
pzorrilla
Newbie

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

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

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

View solution in original post

15 REPLIES 15

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

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

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

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

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

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

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

Clay,

thank you so much for your response, It has been more than useful. Mainly to add the two elements <title/> and <desc/>.

To insert the last row it has been more complicated, not because of inserting the row but because I can not figure out how to add the attribute I want, I've been trying to navigate through the table and find the last row to insert a string corresponding with this new row, but it seems that when i try i reach a column, and the insertion is not possible, however I'll continue testing.

Again, I appreciate so much your time and support.

Paulette

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

Clay!

how do I know that I reached the position inside a table to insert a row using a string and that the insertion would be successful? I tried to get the rows from a table, then I get the oid from the last row and I use the goto_oid() command trying to put the cursor at the end of the row, but when I try to insert a string,

for example, this String: "<row><entry></entry><entry></entry></row>"

I receive a message telling me that the insertion is not possible because it will modify the structure of the table, it seems like the cursor is inside the second entry of my last row, and I don't know how can I move it to the end of the row, let's say, something like this...

<tbody><row1.../><row2.../><row3.../><row><entry></entry><entry></entry></row> | <<[this is the cursor, right here!] </tbody>


I tried to navigate through the table, passing through the rows and entries, but I've hadn't any luck Is there something you could advise me? or maybe something that I'm missing?

Clay, I appreciate in advance your time.

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

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

View solution in original post

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

Clay!

Finally, I decided to obtain the array of rows from the table, get the last element in the array and using goto_oid(oid, -3), insert the desired string, however, now I'm having a problem, the row is not visible, and in order to see it, I have to use "edit -current -untagged" command to see the additional row in the structure or to close the document and open it again. Do you have any idea about why could this be happening? Maybe do I need a command to update the view?

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

Have you tried using in Arbortext Editor the menu selection View > Tables > Table Markup?

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

I already did, but it doesn't work, ummm.. I've been thinking that maybe is because I'm inserting the row using a string instead of commands proper for rows or columns insertion, what I don't understand is why the insertion is successful but is not visually showed in the table.

Thank you,

Paulette

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

Hi Paulette--

I'm not sure why your table wouldn't update right away. When I was testing my addRow() function above, it updated the table display as soon as the function was finished.

You might try calling doc_update_display($doc, 1) (where $doc is your document ID), just in case some other code somewhere else has disabled display updates and that is causing the problem. (Maybe check the rest of your code base for any instances of doc_update_display($doc, 0), which would explain why updates are not occurring when you expect them.)

You might also try playing with ShowGentext to see if that triggers an update to the table display.

--Clay

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

Clay, I found that the scripts I'm trying to modify are using doc_update_display() in other functions, however when I call doc_update_display in my current function to see the current setting, I receive '1' as a response, which as I understand, it means that the display is not suspended, I've been thinking in trying to analyze the other functions and see if any of those disables the updates, however I'm confused because in the function I'm modifying it seems not to be suspended.

Do you have any other ideas of what can be happening? btw, I tried to use ShowGentext but i'm not able to see anything, ummm.. also I was wondering, do you know any other way to modify the attributes of any row of a table using acl commands?

Clay, I appreciate so much your time and help.

Kind regards!

Paulette

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

Hi Paulette--

If it's not doc_update_display() that's stopping the table from updating, then I'm not sure what it would be. Maybe if you quickly switch Table Tag view on and off again that would fix it up?

Regarding modifying row attributes, you should be able to do it in the usual way, i.e. get the OID for the <row> element, and then use oid_modify_attr() to add or change the attribute value.

--Clay

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

Clay!

Thank you so much for all your time and the info you shared with me, at the end what i did was; inserting the last row using this code:

            local toid = tbl_oid_cell(oid_caret()); #returns the ID of the cell

            local tgrid = tbl_obj_grid(toid);       #returns the ID of the grid containing table object toId

            local rows[];

            local nrows = tbl_grid_rowlist(tgrid, rows);

            local rowId = tbl_obj_add(rows[nrows], 0);

and, after that, I get an array containing the rows of the table, then I get the id of the last row and I change the tfoot attribute, using a method i found in another script, which is working but I'm confused about the function is using to modify the attribute, the name of the function is oid_set_attr_or_default() I tried to find it in the script but is not inside and it seems not to be linked with another script, i suppose it works similar to oid_modify_attr(), for the moment everything is working as expected, so thank you so much for all your time and support, it was more than helpful.

this is the code i used to modify the attribute (in case anybody could need it)

     local rows_[];

     local nRows = oid_find_children(oid, rows_, "row"); #oid from table

     oid = $rows_[$nRows];

     goto_oid(oid,-1);

     _xmldlg::_elementSetAttribute('outputclass','tfoot',oid_caret()); #this method contains the oid_set_attr_or_default() function, which I suppose can be changed by oid_modify_attr()

Regards!

Paulette

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

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

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

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

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!

Announcements