Page 1 of 1

add attribute with value on element insert

Posted: Thu Jan 24, 2019 8:41 pm
by akheiljain
I am trying to figure out the right place to configure attribute defaults upon element insert. I would like to add "time" to draft-comment tags and auto populate author upon tag insertion. I have a custom framework created, with storage set to external so it can easily be distributed to other users.

Re: add attribute with value on element insert

Posted: Fri Jan 25, 2019 9:34 am
by Radu
Hi,

For the flexibility that you want (being able to auto generate the date) I think you should try to replace the "draft-comment" content completion entry with a custom Author action.
So if you edit your custom framework configuration in Oxygen, you can define in the "Author->Actions" tab a new custom action with the name "draft-comment" which as an activation XPath uses something like:

Code: Select all

oxy:allows-child-element("para")
https://www.oxygenxml.com/doc/versions/ ... ld-element

and which uses a pre-defined operation called "InsertFragmentOperation":

https://www.oxygenxml.com/doc/versions/ ... toperation

to insert a small XML fragment. The XML fragment can have inside Oxygen editor variables:

https://www.oxygenxml.com/doc/versions/ ... Cvariables

There are editor variables like ${author.name} and ${date(pattern)} which may be interesting to you.

After the action is created, in the "Author->Content Completion" tab you can remove the old "draft-comment" entry and add the action to the content completion window.

Regards,
Radu

Re: add attribute with value on element insert

Posted: Mon Feb 11, 2019 7:21 pm
by akheiljain
Hi Radu,
Thank you for your comments, I still am not able to get it working. Is there a log to see what the issue might be? I followed the instructions in your post and all it inserts now is <draft-comment author=""></draft-comment>, with the cursor within the double quotes. The Action criteria I specified is as follows:
Activation XPath: oxy:allows-child-element("draft-comment")
Operation: ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation
Arguments: fragment = <draft-comment author=${author.name}>${timeStamp}</draft-comment>
all the other arguments are left with default values.

Any help is appreciated.
Thanks

Re: add attribute with value on element insert

Posted: Tue Feb 12, 2019 10:42 am
by Radu
Hi,

I just tested and a "fragment" value of:

Code: Select all

<draft-comment author="${author.name}">${timeStamp}</draft-comment>
works on my side and is properly expanded when the action is invoked.
What version of Oxygen are you using?

Regards,
Radu

Re: add attribute with value on element insert

Posted: Tue Feb 12, 2019 7:56 pm
by akheiljain
Hi Radu,
We are using XML Author 20.1, build 2018101517. And it still doesn't insert it upon inserting the element. I setup a shortcut key to invoke the action, when used adds the author name, but not the timestamp.
Thanks in advance...
Akheil Jain

Re: add attribute with value on element insert

Posted: Wed Feb 13, 2019 10:51 am
by Radu
Hi Akheil,

So the author name editor variable now works, right?
The timestamp editor variable should work as well, it works on my side, just double check that you are using it correctly (${timeStamp}, the editor variable names are case sensitive) in the XML fragment which you set on the InsertFragmentOperation.

Regards,
Radu

Re: add attribute with value on element insert

Posted: Wed Feb 13, 2019 8:39 pm
by akheiljain
Hi Radu,
I may need to rephrase by question, the issue I am running into is the Author Action is not triggered, when I select draft-comment Element for the Element selector or when I hit Enter on my keyboard and select draft-comment element.

Re: add attribute with value on element insert

Posted: Thu Feb 14, 2019 8:28 am
by Radu
Hi,

After you define your custom Author action in the "Document Type" edit dialog in the Author->Actions tab, there is also a tab there called Content Completion. There you have a "Remove Content Completion Items" list from which you can remove the old "draft-comment" entry and then you can add your custom action (which can have the name "draft-comment") to the list of content completion items (you can choose to add it either in the content completion window or in the Elements view or both).

https://www.oxygenxml.com/doc/versions/ ... n-tab.html

Regards,
Radu

Re: add attribute with value on element insert

Posted: Thu Feb 14, 2019 11:06 pm
by akheiljain
Hi Radu,
Thanks for your reply, that is exactly was I was looking for.
Akheil Jain