Reply to: Table – Merging Multiple CellsNovember 28, 2008 at 7:09 pm
But is it possible for me to customize it so that it can be done? If so, where can I change it?
You might also wish to take a step back and ask if the table model supported by your DTD or Schema is really going to support the type of output you wish to produce, or perhaps more clearly, allow you to easily transform from one to the other. If you have complete control over this choice then this is the best time to ask those questions. For example, if you know the majority of your final output will be HTML, then perhaps selecting the HTML table model would be best. That way, when it comes to transforming tables in XML to HTML no transformation (in theory) would be necessary. On the other hand, you may have a specific tool or XSLT that is really good at transforming CALS to HTML, in which case you may wish to use CALS. If you make up your own (not CALS and not HTML) then you should be aware that the special table editing functionality provided for those table models will not apply.
To try to answer your actual question…
There is no way to make simple changes that will enable this feature. For users of XMetaL Author the simplest solution, obviously, would be to wait for a release that contains the function.
In theory though, I think there might be enough APIs in XMetaL Author to create a script that would do this. Such a script would very much depend on the table model you are working with (ie: what does it mean when you “merge cells” because each table model is slightly different). This is why knowing which DTD or Schema you are using is important. However, I suspect that your limited understanding of XML might mean that it would be difficult for you to create such a solution, even if you were to find the appropriate APIs in the XMetaL Developer Programmer's Guide and come up with appropriate logic. If this is a feature you must have you can contact your XMetaL sales rep and ask them for a quote on implementing the feature for your specific case (and at a minimum the people that do this work will want to know which DTD or Schema you are using).
The theoretical script I'm thinking of that might do what you want would have logic similar to the following:
1. Store the beginning and end of the selection as a Range object.
2. Check to see if the user's selection is inside a table using. Using InContextOfType() is probably good enough. If you are not in a table then exit.
3. Find out how many child elements of what you have selected are rows. getNodesByXPath might be a quick way to do this. This is where you might need to know what table model you are using (HTML uses
4. Find out how many first child elements of the user's selection are table cells. Again, this is probably going to be specific to the table model and different for HTML and CALS. You might use getNodesByXPath, or you might try to walk the DOM and use InContextOfType(), or their might be other smarter ways to do this.
5. Place a Range at the start of the user's original selection. I think at this point we can assume we are somewhere inside a table cell.
6. Merge right as many times as required to merge everything the user selected. This is why we counted the number of cells in step #4. One API that does this is MergeCellRight().
7. Try to restore something similar to the user's original selection. This might be tricky because you have changed a bunch of nodes inside it, so you might need to make a new selection. This is why we stored start and end Range objects in step #1.
Actually getting it to work would be the hard part. In some cases MergeCellRight() may fail. That would likely be the case if a cell is already merged across rows (possible in some table models), in which case do you just stop? Do you back up and undo all the merges you already did? Does the script need to be smart enough to figure out that this would happen ahead of time and tell the user they can't do what they want to do?