Another important addition in the second draft of the Schematron QuickFix specification is the possibility to define generic quick fixes. Using a generic quick fix, the developer can generate multiple similar fixes using the values provided by an XPath expression.
In the first draft of the SQF specification, it was not possible to have a dynamic
amount of quick fixes for a Schematron error. The developer should specify the quick
fixes presented for a Schematron error. They could only control whether or not a quick
fix will be presented to the user by using the @use-when
attribute.
To create a generic quick fix, the SQF developer needs to set the
use-for-each
attribute for the sqf:fix
element. The value
of the use-for-each
attribute must be an XPath expression. For each item of
the evaluated XPath expression, a quick fix is provided to the user. The context inside
of the quick fix will be the current Schematron error context. To access the value of
the current item from the XPath expression, a built-in variable
$sqf:current
can be used.
Example 20. A Generic QuickFix that provides a quick fix to remove each item from a list
<sqf:fix id="removeAnyItem" use-for-each="1 to count(li)"> <sqf:description> <sqf:title>Remove item #<sch:value-of select="$sqf:current"/></sqf:title> </sqf:description> <sqf:delete match="li[$sqf:current]"/> </sqf:fix>
Using generic quick fixes, the SQF developer can now provide a dynamic number of fix actions depending on a set of values from the current document or they can use an XPath expression to get the values from external documents.