Refactoring: delete an attribute value

Are you missing a feature? Request it's implementation here.
MarcinM
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">

Radu
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

Hi,

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:

https://www.oxygenxml.com/doc/versions/ ... tools.html

The XML operation descriptor file would look like this:

Code: Select all

<refactoringOperationDescriptor 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.oxygenxml.com/ns/xmlRefactoring" id="normalizeAttrValues" name="Normalize Attr Values">
<description>Normalize attribute values.</description>
<script type="XSLT" href="normalizeAttrValues.xsl"/>
</refactoringOperationDescriptor>
and the XSLT would look like this:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@att">
<xsl:attribute name="att" select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>
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.


Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply