Page 1 of 1

In "Add/Change attribute" refactoring, support value XPath expressions

Posted: Wed Mar 01, 2023 8:22 pm
by chrispitude
Let's say I have a table like this:

image.png

I would like each row to have an @id value equivalent to its first-column value, so it can be specifically referenced.

It would be great if the Add/Change attribute refactoring operation had a "Evaluate value as XPath" that would evaluate the given value using the XPath 3.0 xsl:evaluate() function. Then, I could run the refactoring operation to set the @id attribute, with the value specified as

Code: Select all

string(entry[1])
Special characters could be handled, if needed:

Code: Select all

string(entry[1]) => replace("[^-.A-Za-z0-9_:]+", "_")
In our actual DITA content, we have multiple such .dita topic files of error message tables, each with many (potentially hundreds) of rows. If the refactoring operation had such a feature, it would be trivial to process the entire set in one refactoring operation on the selected resources.

A sample DITA topic file is attached:

error_messages.zip

Re: In "Add/Change attribute" refactoring, support value XPath expressions

Posted: Wed Mar 01, 2023 10:45 pm
by chrispitude
Here is the refactoring operation I used for now:

set-evaluated-attribute.zip

Re: In "Add/Change attribute" refactoring, support value XPath expressions

Posted: Thu Mar 02, 2023 8:42 am
by Radu
Hi Chris,
Makes sense, thanks for sharing your samples and the custom XML refactoring action you created.
I had a similar need when replying to an older forum thread:
post66324.html#p66324
So there is already this registered issue, I added your details to it:
EXM-50799 Add/change attribute value could be an xpath expression

Regards,
Radu