Refactoring: delete an attribute value

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

Refactoring: delete an attribute value

Post by MarcinM »

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: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Refactoring: delete an attribute value

Post by Radu »

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
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Refactoring: delete an attribute value

Post by chrispitude »

We need a similar solution for DITA authoring in Oxygen XML Author. Specifically, we need a way to remove a specific profiling condition value from the @props attribute throughout the entire project.
  • Delete just that value from @props if there are multiple values
  • Remove the @props attribute completely if it becomes empty
  • Delete <ph props=”…”>…</ph> span elements that become superfluous because of this
The last item is because the editor is smart enough to create a <ph> span to apply a condition to a portion of text, and so the removal process should be similarly smart.
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Refactoring: delete an attribute value

Post by chrispitude »

Hi all,

I've submitted an enhancement request for a new XML refactoring operation that can delete a value out of an attribute.
Post Reply