add attribute with value on element insert

Post here questions and problems related to oXygen frameworks/document types.
akheiljain
Posts: 18
Joined: Wed Nov 28, 2018 8:13 pm

add attribute with value on element insert

Post by akheiljain » Thu Jan 24, 2019 8:41 pm

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.

Radu
Posts: 6498
Joined: Fri Jul 09, 2004 5:18 pm

Re: add attribute with value on element insert

Post by Radu » Fri Jan 25, 2019 9:34 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

akheiljain
Posts: 18
Joined: Wed Nov 28, 2018 8:13 pm

Re: add attribute with value on element insert

Post by akheiljain » Mon Feb 11, 2019 7:21 pm

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

Radu
Posts: 6498
Joined: Fri Jul 09, 2004 5:18 pm

Re: add attribute with value on element insert

Post by Radu » Tue Feb 12, 2019 10:42 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

akheiljain
Posts: 18
Joined: Wed Nov 28, 2018 8:13 pm

Re: add attribute with value on element insert

Post by akheiljain » Tue Feb 12, 2019 7:56 pm

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

Radu
Posts: 6498
Joined: Fri Jul 09, 2004 5:18 pm

Re: add attribute with value on element insert

Post by Radu » Wed Feb 13, 2019 10:51 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

akheiljain
Posts: 18
Joined: Wed Nov 28, 2018 8:13 pm

Re: add attribute with value on element insert

Post by akheiljain » Wed Feb 13, 2019 8:39 pm

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.

Radu
Posts: 6498
Joined: Fri Jul 09, 2004 5:18 pm

Re: add attribute with value on element insert

Post by Radu » Thu Feb 14, 2019 8:28 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

akheiljain
Posts: 18
Joined: Wed Nov 28, 2018 8:13 pm

Re: add attribute with value on element insert

Post by akheiljain » Thu Feb 14, 2019 11:06 pm

Hi Radu,
Thanks for your reply, that is exactly was I was looking for.
Akheil Jain

Post Reply