SQF and DITA classes
Posted: Mon Feb 11, 2019 8:20 pm
I'm struggling to formulate a Schematron Quickfix that can replace the value of a class attribute with the correct syntax for DITA - it seems to unavoidably strip the required trailing space character.
My current code:
This works, in as much as the assert fires when a class value is not in $foo, and Oxygen offers the valid class values in an SQF popup. However, it seems that the sqf:replace action normalises whitespace, so for example "- topic/topic special/element " becomes "- topic/topic special/element", which is not valid for DITA. What I'm really puzzled about is that the value-of in sqf:title correctly evaluates as "- topic/topic special/element " in the SQF popup.
My suspicion is that this is something to do with attribute-value normalisation - "If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters...", and DITA class attributes are indeed of type CDATA - but I can't figure out a way of confirming this for sure.
I wondered if using XSLT constructors inside the SQF actions - something like this: - would get me where I needed to be, but this just results in the attribute being removed entirely from the document. I can live with the behaviour as it is, but if there's a way to retain the space, I'd really appreciate hearing about it! 
My current code:
Code: Select all
<xsl:variable name="foo" as="attribute(@class)+' select="doc('lookup.xml')/elements/@class"/>
[...]
<sch:rule context="*[@class]">
<sch:assert sqf:fix="qux" test="@class = $foo">The class value isn't in $foo but should be</sch:assert>
</sch:rule>
[...]
<sqf:fix id="qux" use-for-each="$foo">
<sqf:description>
<sqf:title>Replace class value with "<xsl:value-of select="string($sqf:current)"/>
</sqf:description>
<sqf:replace match="@class" target="{'class'}" node-type="attribute">
<xsl:value-of select="string($sqf:current)"/>
</sqf:replace>
</sqf:fix>
My suspicion is that this is something to do with attribute-value normalisation - "If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters...", and DITA class attributes are indeed of type CDATA - but I can't figure out a way of confirming this for sure.
I wondered if using XSLT constructors inside the SQF actions - something like this:
Code: Select all
<sqf:replace [...]><xsl:attribute select="$sqf:current"/></sqf:replace>
