Pages: 1
Print
Author Topic: CALS Table Manipulation  (Read 454 times)
scotth
Member

Posts: 35


« on: November 28, 2011, 02:11:33 PM »

I am using XMAX 6.0 for the project that I am currently working on. My schema makes use of CALS tables. I am able to insert these tables properly. However, I am running into some issues when performing certain manipulations after the fact. First, adding a thead or tfoot after the table insertion results in a thead or tfoot that is not rendered in XMAX for display and edit by the user. Second, I cannot seem to add tgroup elements and have them rendered in the same manner that the initial tgroup is rendered. I looked over the programmer documentation, but could not find an additional methods for adding these elements. What is the best way to perform each of these actions in XMAX?
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1548



WWW
« Reply #1 on: November 29, 2011, 03:28:50 PM »

There are no specific methods for inserting tgroup, thead, tbody, or tfoot elements after a table has been inserted (thead and tfoot can be inserted when a table is created, as documented for the InsertCALSTable API).

You should be able to create a Range, move it after a tgroup and then insert a new tgroup there. Your new tgroup will need to have at least one row with at least one entry to be visible. Note that your DTD will need to support multiple tgroup elements inside a table (the CALS standard itself allows this, but some schemas might restrict it to just one). Here's an example:

Code:
//XMetaL Script Language JScript:
var rng = ActiveDocument.Range;
if (rng.InContextOfType("tablecell")) {
if (rng.MoveToElement("tgroup",false)) {
rng.SelectAfterNode(rng.ContainerNode);
//build up your tgroup as a string here, using whatever logic makes the most sense to you (loops, etc)...
var tgroup = '<tgroup cols="1"><colspec colnum="1" colname="col1" colwidth="*"/><thead><row><entry colname="col1"></entry></row></thead><tbody><row><entry colname="col1"></entry></row></tbody><tfoot><row><entry colname="col1"></entry></row></tfoot></tgroup>';
rng.PasteString(tgroup);
}
}

Note that in this case your DTD needs to support <tfoot> inside <tgroup> in your CALS table, which is the standard OASIS model. One example of a DTD that does not allow tfoot is DITA.

Anytime you make changes to a table structure in script that are not immediately rendered (this would be the case pretty much anytime you do anything but insert a complete table, or mimic a user action as above) you can call the API formatGraphicTable() to force it to be rendered as a table, or update those bits that are not currently rendered as such. An explanation of why this is the case is included in the docs for this API. If the script above was altered to use DOM or individual InsertElement() calls then that would be necessary.

You may find it easier to enable Plain Text view in XMAX when working with this type of code as it is possible to insert parts of a table that cannot be rendered as a table due to lack of entry elements, etc. Or you might code for XMetaL Author and then once it is working there move it to your XMAX application.
« Last Edit: November 29, 2011, 03:34:14 PM by Derek Read » Logged
Pages: 1
Print
Jump to: