Page 1 of 1

How to modify attributes with editor variables?

Posted: Tue Oct 24, 2017 5:13 am
by avanlooveren
I need to replace all attributes with a particular name in a single document to have a value of UUID (the editor variable "{uuid}"). I don't think Find/Replace, even with regex, is capable of this.

I'm trying to configure a custom Author action with ChangeAttributeOperation, but I wonder if I'm going about this all wrong. I set the elementLocation to "//*", but I cannot seem to get more than one attribute value to update.

Any help appreciated. Also, is it possible to enable this in Text mode? Thanks!

Re: How to modify attributes with editor variables?

Posted: Tue Oct 24, 2017 5:20 pm
by sorin_carbunaru
Hello,

You could use a custom XML Refactoring operation (https://www.oxygenxml.com/doc/versions/ ... tions.html). I did just that to see if it works (and it does work), starting from the default Add/Change attribute operation, and instead of requesting an attribute value from the user, I generated one in the operation's XQuery script, using the generate-id() function.

You can find my try at http://www.oxygenxml.com/forum/files/custom%20change%20attributes.zip.

Best regards,
Sorin Carbunaru
oXygen XML

Re: How to modify attributes with editor variables?

Posted: Thu Jan 25, 2018 4:47 am
by avanlooveren
Sorin,

First, a big THANK YOU. You and your team are always so thorough with your responses and this was no exception.

Priorities shifted, so a lot of time passed before I got to try out your solution, but it works. (Of course, it does, and of course your wonderful product was ready to address my need.)

My tweak, since I did want UUID and not the "element position" that generate-id() produces, was to supplement your provided XQuery with:

Code: Select all

declare namespace uuid = "java:java.util.UUID"

and then use

Code: Select all

uuid:randomUUID()


Thanks again,

-Andre