Refactoring: delete an attribute value

Are you missing a feature? Request it's implementation here.
Posts: 1
Joined: Thu Nov 15, 2018 1:28 pm

Refactoring: delete an attribute value

Post by MarcinM » Thu Nov 15, 2018 1:41 pm

We're doing some clean-up of our DITA files now and have one attribute value that we want to get rid of.
The only way I came up with so far is to use "replace in attribute value", find all instances of the attribute I want, and replace it with nothing. This, however, leaves attributes with redundant spaces where there was more than one value (I already deleted all elements that have only this one attribute, we want to get rid of those entirely). I solved this manually, but it's not very convenient.

Can there be a refactoring operation that deletes a certain value from an attribute and any leftover spaces?

Examples of spaces, assuming that a "value2" was replaced with nothing:

Code: Select all

</tag @att=" value1">
</tag @att="value1 ">
</tag @att="value1 value3">

Posts: 6512
Joined: Fri Jul 09, 2004 5:18 pm

Re: Refactoring: delete an attribute value

Post by Radu » Mon Nov 19, 2018 10:33 am


I would see this refactoring as being done in two waves:

1) Remove the value from the attribute (which you have already done using our default refactoring action).
2) Normalize the values of all existing attributes (remove leading and trailing spaces and also remove consecutive spaces between value tokens).
For (2) you can implement your own XML Refactoring action based on XSLT: ... tools.html

The XML operation descriptor file would look like this:

Code: Select all

xmlns="" id="normalizeAttrValues" name="Normalize Attr Values">
<description>Normalize attribute values.</description>
<script type="XSLT" href="normalizeAttrValues.xsl"/>
and the XSLT would look like this:

Code: Select all

<xsl:stylesheet xmlns:xsl=""
<xsl:template match="node() | @*">
<xsl:apply-templates select="node() | @*"/>

<xsl:template match="@att">
<xsl:attribute name="att" select="normalize-space(.)"/>
The XSLT needs to be changed depending on that specific XSLT attribute you want to match.
Once you have the XML descriptor file and the XSLT in a folder, you can refer to that folder from the Oxygen Preferences->"XMl Refactoring" page and after this when using the "XMl Refactoring" action from the "Tools" main menu you should have the new action available there.

Radu Coravu
<oXygen/> XML Editor

Post Reply