Using SQF on Schematron files

Oxygen general issues.
scottbdr
Posts: 50
Joined: Tue Jul 21, 2009 1:48 am

Using SQF on Schematron files

Post by scottbdr »

I'm trying to create a Schematron Quickfix to enforce the authoring standards on our Schematron files. Works great until I needed to add a schematron element because the SQF can't tell the element I was trying to add wasn't just Schematron needing evaluation. Example, the following (obviously wrong) SQF rule tries to add a element <sch:value-of select='$DIAGNOSTIC_FOOTER'> into the schematron document being fixed (in bold below), but of course it just gets evaluated because it's schematron. I know t XSLT uses a namespace-alias for this sort of thing, what's the approach in this case?

Thanks Scott

<sch:pattern id="sqf-add-diag-ft">
<sch:rule context="sch:assert | sch:report">
<sch:assert test="sch:value-of[@select = '$DIAGNOSTIC_FOOTER']" sqf:fix="sqf-add-diag-ft" role="error" id="sch0004"><sch:name/> should have value-of for the diagnostic footer .</sch:assert>
<sch:let name="var-name" value="'$DIAGNOSTIC_FOOTER'"></sch:let>
<sqf:fix id="sqf-add-diag-ft">
<sqf:description>
<sqf:title>Add diagnostic footer</sqf:title>
</sqf:description>
<sqf:add position="last-child" xml:space="preserve">
<sch:value-of select="$var-name"/></sqf:add>
</sqf:fix>
</sch:rule>
</sch:pattern>
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Using SQF on Schematron files

Post by tavy »

Hi Scott,

In this case you can use the "xsl:element" and "xsl:attribute" to generate the content. Something like this"

Code: Select all

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
    xmlns:sqf="http://www.schematron-quickfix.com/validator/process" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <sch:ns uri="http://purl.oclc.org/dsdl/schematron" prefix="sch"/>
    <sch:pattern id="sqf-add-diag-ft">
        <sch:rule context="sch:assert | sch:report">
            <sch:assert test="sch:value-of[@select = '$DIAGNOSTIC_FOOTER']"
                sqf:fix="sqf-add-diag-ft" role="error" id="sch0004"><sch:name/> should have value-of
                for the diagnostic footer .</sch:assert>
            <sch:let name="var-name" value="'$DIAGNOSTIC_FOOTER'"/>
            
            <sqf:fix id="sqf-add-diag-ft">
                <sqf:description>
                    <sqf:title>Add diagnostic footer</sqf:title>
                </sqf:description>
                <sqf:add position="last-child">
                    <xsl:element name="sch:value-of">
                         <xsl:attribute name="select" select="$var-name"/>
                     </xsl:element>
                </sqf:add>
            </sqf:fix>
        </sch:rule>
    </sch:pattern>
</sch:schema>
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
scottbdr
Posts: 50
Joined: Tue Jul 21, 2009 1:48 am

Re: Using SQF on Schematron files

Post by scottbdr »

Thanks for that... I tried that earlier but I think I was seeing error results from a previous iteration when I did the QF - have to remember to re-validate the document before trying the QF again. Just getting started with SQF so getting a few lessons as I go. Excited about using it now!
scottbdr
Posts: 50
Joined: Tue Jul 21, 2009 1:48 am

Re: Using SQF on Schematron files

Post by scottbdr »

Speaking of lessons... found another problem too - xml:space="preserve" doesn't work on the sqf:add if using the xsl:
Could not generate quick fix 'sqf-add-diag-ft'

I think this is what I may have been seeing before. Removing it and formatting with xsl:text gets things to work.
Post Reply