Making @class attributes available to refactoring operations
Posted: Tue Feb 07, 2023 3:49 am
When processing or validating DITA, it can be useful to access the @class attribute. For example, this template:
could be rewritten as follows:
Plus, the second method automatically considers user specializations whereas the first method does not.
In Oxygen,
The testcase defines a Schematron check for specialized elements, and an interactive quick-fix that allows you to unspecialize an element. The quick-fix leaves lingering explicit @class attributes in the DITA source file, so I would need to update the code to fix that.
The testcase also defines a refactoring operation that tries to unspecialize entire DITA topics. It does not work because there are no @class attributes made available in refactoring operations.
But, if @class attributes were made available in refactoring operations, then existing refactoring operations could break. For example, a template that copied @* into a new element would also copy the refactoring-added @class attribute.
Is there some clever way that @class could be accessed in refactoring operations without interfering with existing refactoring operations? For example, could refactoring operations populate the @class attribute values before the operation, apply the transformation, then clean them up after the operation? Or would this break some other theoretically possible workflow where @class attributes were explicitly present in the source file (or added!) and the user does not want them to be cleaned up?
Just thinking out loud for now, but I could see a lot of use for refactoring operations being more knowledgeable about specializations and specialization ancestry!
Code: Select all
<xsl:template match="addressdetails|administrativearea|b|codeph|coords|country|delim|em|equation-inline|equation-number|filepath|hwcontrol|i|lcAreaCoords|lcAreaCoords2|light-b|line-through|locality|localityname|menucascade|msgph|oper|organizationname|organizationnamedetails|overline|partno|ph|postalcode|repsep|sep|strong|sub|sup|synph|systemoutput|thoroughfare|tt|u|uicontrol|userinput|var">
...
</xsl:template>
Code: Select all
<xsl:template match="*[contains-token(@class, 'topic/ph')]">
...
</xsl:template>
In Oxygen,
- Schematron checks see @class values.
- This includes interactive editor checks and batch validation.
- XSLT templates used inside the Schematron file also see @class values.
- XSLT refactoring operations do not see @class values.
The testcase defines a Schematron check for specialized elements, and an interactive quick-fix that allows you to unspecialize an element. The quick-fix leaves lingering explicit @class attributes in the DITA source file, so I would need to update the code to fix that.
The testcase also defines a refactoring operation that tries to unspecialize entire DITA topics. It does not work because there are no @class attributes made available in refactoring operations.
But, if @class attributes were made available in refactoring operations, then existing refactoring operations could break. For example, a template that copied @* into a new element would also copy the refactoring-added @class attribute.
Is there some clever way that @class could be accessed in refactoring operations without interfering with existing refactoring operations? For example, could refactoring operations populate the @class attribute values before the operation, apply the transformation, then clean them up after the operation? Or would this break some other theoretically possible workflow where @class attributes were explicitly present in the source file (or added!) and the user does not want them to be cleaned up?
Just thinking out loud for now, but I could see a lot of use for refactoring operations being more knowledgeable about specializations and specialization ancestry!