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

Delete attribute from table on paste

bbender
Visitor

Delete attribute from table on paste

Hello Adepters,

I would like to delete attributes from a table on paste using 5.4M070. For example when copying & pasting a row, delete @id on all elements including row, entry, and para. I have tried:
1) ACL paste callback that modifies xml in buffer_doc
2) JS AOMPaste event that accesses pasted xml using relatedRange

I've learned from testing and the forum, table markup is not accessible by object id when formatted (table markup is off).

With ACL, using oid to access the table components I saw the behavior:
(1) if an entire table is copied/pasted, all attributes on elements are deleted as wanted;
(2) if a row is copied/pasted, only the para has the attribute deleted. Interestingly, if a row is copied the paste buffer row is wrapped in table markup.
This behavior makes sense because the table and para tags are displayed in the Editor, unlike the other table markup that is hidden. Since object id (oid) does not work, I speculate accessing the table object id (toid) of the hidden parts might be an option instead, but I'm uncertain how to do this and if it's possible at all.

With JS, I did not pursue that any further because the row markup was not accessible, at least when I checked the markup was existent via event.relatedRange.toMarkupString().

Any recommendations? To simplify the process I want to avoid turning table markup on and handle it "auto-magically."

Thank you!
Bryan
Tags (2)
8 REPLIES 8

Delete attribute from table on paste

Hello Adepters,

I would like to delete attributes from a table on paste using 5.4M070. For example when copying & pasting a row, delete @id on all elements including row, entry, and para. I have tried:
1) ACL paste callback that modifies xml in buffer_doc
2) JS AOMPaste event that accesses pasted xml using relatedRange

I've learned from testing and the forum, table markup is not accessible by object id when formatted (table markup is off).

With ACL, using oid to access the table components I saw the behavior:
(1) if an entire table is copied/pasted, all attributes on elements are deleted as wanted;
(2) if a row is copied/pasted, only the para has the attribute deleted. Interestingly, if a row is copied the paste buffer row is wrapped in table markup.
This behavior makes sense because the table and para tags are displayed in the Editor, unlike the other table markup that is hidden. Since object id (oid) does not work, I speculate accessing the table object id (toid) of the hidden parts might be an option instead, but I'm uncertain how to do this and if it's possible at all.

With JS, I did not pursue that any further because the row markup was not accessible, at least when I checked the markup was existent via event.relatedRange.toMarkupString().

Any recommendations? To simplify the process I want to avoid turning table markup on and handle it "auto-magically."

Thank you!
Bryan

Delete attribute from table on paste

Hi Bryan-



I would have to see exactly what you've tried in terms of
getting/modifying table elements in your callbacks. You should be able
to do it once you get the right OID, but sometimes doing that can be
tricky, as you may not be able to walk the table markup tree in the same
way you would with non-table markup. Can you post a copy of the ACL
paste callback that you tried?



--Clay



Clay Helberg

Senior Consultant

TerraXML


RE: Delete attribute from table on paste

Hello Clay,

Here is my code:

function pasteCallback(doc, buffername, op) {
if ( op == 2 ) {
# create paste buffer doc
set paste = temp;
local bdoc = buffer_doc("default");
#response( "bdoc content pre-clean-up: " . doc_content(bdoc) );
# remove diffid, astid, modtime attributes on paste buffer
for (o = oid_first_tag(bdoc); oid_valid(o); o = oid_forward(o)) {
if (oid_has_attr(o, "id")) { oid_delete_attr(o, "id") }}
#response( "bdoc content post-clean-up: " . doc_content(bdoc) );
set paste=default;
paste default;
return -1;
}
}

# add callbacks
doc_add_callback(current_doc(), 'paste', 'pasteCallback');

Thanks,
Bryan

Delete attribute from table on paste

Hi Bryan-



You might have better luck if you try using oid_find_child_attrs()
instead of trying to iterate over OIDs using oid_forward(). So, replace
your loop with something like this:



local idoids[];

oid_find_child_attrs(oid_root(bdoc),idoids,"id");

for (o in idoids) {

oid_delete_attr(idoids[o],"id");

}



FWIW, when I tried to replicate your result using standard axdocbook, I
found that when pasting a single row, the paste buffer seemed to
automatically do what you are asking for, i.e. it stripped out "id"
attrs without executing any code at all. I guess you must have something
in your custom doctype that prevents that.



--Clay



Clay Helberg

Senior Consultant

TerraXML


Delete attribute from table on paste

I also have always had good results using Clay's array sample for ACL to modify/delete attributes.

RE: Delete attribute from table on paste

Clay,

I tried out your code. It still does not work on deleting attributes from a table. Granted, the code is correct but something about the buffer_doc containing a table causes different behavior. My response codeshows the attribute removal, but when I check the pasted xml, none of theattributes are deleted.

As clarification, I actually want to delete attributes named diffid, astid, and modtime, not id. I wanted to shorten the code example here and didn't expect a possible default behavior. These 3attributes are CDATA IMPLIED, so removal of them should not cause validation issues. Curious about your comment, I added @id to the DTD and xml and verified theautomatic deletion of ids from table. Is there a way to extend this default deletion to include these other attributes? I noticed though id was only deleted if it was set to ID in the DTD.

Also, the reason I chose to iterate over all the oids was because the paste buffer might not have a root, like if 2 paras were copied and pasted.

So, I'm still at a loss to a solution.

Thank you so far!

Bryan

Delete attribute from table on paste

Hi Bryan-



I think you're right, the auto-cleanup of ID attrs during paste is
probably controlled by the DTD defining those attrs as ID. I don't know
of a workaround other than to declare them as ID. Well, wait--maybe if
you declare them as id attributes in the DCF file that would suffice.
Don't have the syntax for that off the top of my head and I have to run
in a minute, but it shouldn't be hard to find in the documentation. No
idea if it would work, but might be worth a try...



The only other suggestion I have is to do an end-run around the paste
mechanism by using insert(markup) instead of the paste command. Since
you can see the desired result in your response message, just use that
same markup string you're passing to response() as the argument to
insert(), which will insert it into the document as parsed content.



--Clay



Clay Helberg

Senior Consultant

TerraXML


RE: Delete attribute from table on paste

I just wanted to close-out this thread by saying I resolved the issue by using another callback named tbl_obj_add_after, which iscalled after agrid, column, or row is inserted into an existing table. The functionprovides the toid of the newly inserted xml, which I can then use to access the oid to remove element attributes. Removal of attributes on rows is simple enough, but columns require using some table functions to access only the related column entries.


Best,


Bryan


Announcements