Should Schematron Quick Fixes be Offered for Attributes?

This should cover W3C XML Schema, Relax NG and DTD related problems.
Eddie
Posts: 106
Joined: Wed Dec 18, 2013 3:07 am

Should Schematron Quick Fixes be Offered for Attributes?

Post by Eddie »

Hello,
Using Author 17.0. Working in DITA.
Apologies if this is not the right place to ask, but I can't find any relevant information on this:

I have a schematron that checks ids to see if they contain underscores, which we do not allow.
I have set a quick fix to replace underscores with hyphens, like this:

Code: Select all

        <sch:rule context="@id">
<sch:report test="matches(.,'_')" sqf:fix="ReplaceUnderscore1" role="error">IDs must not contain underscores.</sch:report>
<sqf:fix id="ReplaceUnderscore1">
<sqf:description>
<sqf:title>Replace the underscores with hyphens.</sqf:title>
</sqf:description>
<sqf:stringReplace match="text()" regex="_">-</sqf:stringReplace>
</sqf:fix>
</sch:rule>
The schematron finds the underscores but the quick fix is not offered.
I have tried the same quick fix with the context set as an element, and the quick fix is offered and works, so I'm assuming the problem is that quick fixes don't work for attributes. Is that correct? As I said, I can't find a definitive statement on this anywhere, and it seems strange that the schematron finds the error but the quick fix isn't offered.
Cheers,
Eddie.
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

Re: Should Schematron Quick Fixes be Offered for Attributes?

Post by tavy »

Hi Eddie,

The sqf:stringReplace operation works only for text nodes, not for attribute values.
http://schematron-quickfix.github.io/sq ... tml#d0e921

The quick fix is not offered because your XPath expression from the stringReplace operation is not correct "@id/text()". You cannot use the "text()" in the context of an attribute. The "text()" selects all text node children of the context node.

If you want to change the attribute value you can use the sqf:replace operation. For example you can use this operation:

Code: Select all

<sqf:replace node-type="attribute" target="id" select="replace(., '_', '-')"/>
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
Eddie
Posts: 106
Joined: Wed Dec 18, 2013 3:07 am

Re: Should Schematron Quick Fixes be Offered for Attributes?

Post by Eddie »

Many thanks, Octavian.
That's perfect.

Cheers,
Eddie.
Post Reply