How to debug SQF?

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Martin Holmes
Posts: 10
Joined: Sat Mar 12, 2005 12:37 am

How to debug SQF?

Post by Martin Holmes »

Hi all,
I have a fairly complex Schematron QuickFix which attempts to merge two elements, and it fails when I try to run it with the unhelpful message "Could not generate quick fix 'mergeCits'." No other feedback is provided, and I have no way of knowing what's causing the problem. The Schematron file containing the QuickFix is valid (Oxygen reports "[Schematron + SQF] Validation successful"). The code itself is below (it's a bit verbose at the moment). Is there any way to see what's causing the error?

Code: Select all

<pattern>
    <rule context="tei:TEI[@n='matchCits']/descendant::tei:cit[following-sibling::tei:cit]">
      <let name="cit1" value="."/>
      <let name="cit2" value="following-sibling::tei:cit[1]"/>
      <!-- We can only merge simple cases. -->
      <let name="canMerge" value="xs:boolean((count($cit1/tei:quote/tei:phr) lt 3) and 
                                  (count($cit2/tei:quote/tei:phr) lt 3) and 
                                  (count($cit1/tei:quote/tei:seg) lt 3) and 
                                  (count($cit2/tei:quote/tei:seg) lt 3))"/>
      <assert test="not((deep-equal($cit1/tei:quote/tei:bibl[2], $cit2/tei:quote/tei:bibl[2])) and (deep-equal($cit1/tei:quote/tei:seg[1], $cit2/tei:quote/tei:seg[1])))" sqf:fix="mergeCits">
        WARNING: This cit and the immediately-following cit appear to be duplicates.
      </assert>
      <sqf:fix id="mergeCits">
        <sqf:description>
          <sqf:title>Merge two cits which are duplicates and replace the second with an intermediate pointer.</sqf:title>
        </sqf:description>
        
        <!-- Add the pointer which will redirect existing links to the cit1 id. -->
        <sqf:add position="after">
          <xsl:text>&#x0a;&#x0a;          </xsl:text><ptr xmlns="http://www.tei-c.org/ns/1.0" corresp="cit:{$cit1/@xml:id}" xml:id="{$cit2/@xml:id}"/><xsl:text>&#x0a;&#x0a;          </xsl:text>
        </sqf:add>
        
        <sqf:add position="after" use-when="not($canMerge)">
          <xsl:text>&#x0a;&#x0a;          </xsl:text>
          <xsl:comment>These two cits are a bit too complicated for automatic merging.
          A pointer has been inserted, but you'll have to do the merge manually. :-(</xsl:comment>
        </sqf:add>
        
        <!-- Here we need to merge the two cits. -->
        <sqf:replace use-when="$canMerge" match=".">
          <xsl:variable name="citIndent" as="xs:string" select="xs:string($cit1/node()[1][self::text()])"/>
          <xsl:variable name="quoteIndent" as="xs:string" select="xs:string($cit1/tei:quote/node()[1][self::text()])"/>
          <xsl:variable name="rep" as="element(tei:cit)">
            <xsl:copy>
              <xsl:copy-of select="@*"/>
              <xsl:sequence select="$citIndent"/>
              <quote xmlns="http://www.tei-c.org/ns/1.0">
                
                <!-- First p-phrs and following bibl elements that go with them. -->
                <xsl:for-each select="child::tei:quote/tei:phr[@type='p']">
                  <xsl:sequence select="$quoteIndent"/>
                  <xsl:copy-of select="."/>
                  <xsl:sequence select="$quoteIndent"/>
                  <xsl:copy-of select="following-sibling::*[1][self::tei:bibl]"/>
                </xsl:for-each>
                <xsl:for-each select="$cit2/tei:quote/tei:phr[@type='p']">
                  <xsl:variable name="currCit2Phr" as="element(tei:phr)" select="."/>
                  <xsl:if test="not($cit1/tei:quote/tei:phr[@type='p'][deep-equal(., $currCit2Phr)])">
                    <xsl:sequence select="$quoteIndent"/>
                    <xsl:copy-of select="$currCit2Phr"/>
                    <xsl:variable name="assocBibl" select="$currCit2Phr/following-sibling::*[1][self::tei:bibl]"/>
                    <xsl:if test="$assocBibl and not($cit1/tei:quote/tei:bibl[deep-equal(., $assocBibl)])">
                      <xsl:sequence select="$quoteIndent"/>
                      <xsl:copy-of select="$assocBibl"/>
                    </xsl:if>
                  </xsl:if>
                </xsl:for-each>
                
                <!-- Next n-phrs and following bibl elements that go with them. -->
                <xsl:for-each select="child::tei:quote/tei:phr[@type='n']">
                  <xsl:sequence select="$quoteIndent"/>
                  <xsl:copy-of select="."/>
                  <xsl:sequence select="$quoteIndent"/>
                  <xsl:copy-of select="following-sibling::*[1][self::tei:bibl]"/>
                </xsl:for-each>
                <xsl:for-each select="$cit2/tei:quote/tei:phr[@type='n']">
                  <xsl:variable name="currCit2Phr" as="element(tei:phr)" select="."/>
                  <xsl:if test="not($cit1/tei:quote/tei:phr[@type='n'][deep-equal(., $currCit2Phr)])">
                    <xsl:sequence select="$quoteIndent"/>
                    <xsl:copy-of select="$currCit2Phr"/>
                    <xsl:variable name="assocBibl" select="$currCit2Phr/following-sibling::*[1][self::tei:bibl]"/>
                    <xsl:if test="$assocBibl and not($cit1/tei:quote/tei:bibl[deep-equal(., $assocBibl)])">
                      <xsl:sequence select="$quoteIndent"/>
                      <xsl:copy-of select="$assocBibl"/>
                    </xsl:if>
                  </xsl:if>
                </xsl:for-each>
                
                <!-- Next segs and following bibl elements that go with them. -->
                
                <xsl:for-each select="child::tei:quote/tei:seg">
                  <xsl:sequence select="$quoteIndent"/>
                  <xsl:copy-of select="."/>
                  <xsl:sequence select="$quoteIndent"/>
                  <xsl:copy-of select="following-sibling::*[1][self::tei:bibl]"/>
                </xsl:for-each>
                <xsl:for-each select="$cit2/tei:quote/tei:seg">
                  <xsl:variable name="currCit2Seg" as="element(tei:seg)" select="."/>
                  <xsl:if test="not($cit1/tei:quote/tei:seg[deep-equal(., $currCit2Seg)])">
                    <xsl:sequence select="$quoteIndent"/>
                    <xsl:copy-of select="$currCit2Seg"/>
                    <xsl:variable name="assocBibl" select="$currCit2Seg/following-sibling::*[1][self::tei:bibl]"/>
                    <xsl:if test="$assocBibl and not($cit1/tei:quote/tei:bibl[deep-equal(., $assocBibl)])">
                      <xsl:sequence select="$quoteIndent"/>
                      <xsl:copy-of select="$assocBibl"/>
                    </xsl:if>
                  </xsl:if>
                </xsl:for-each>
                
              </quote>
              
              <!-- Now any remaining following-siblings of quote. -->
              <xsl:sequence select="$citIndent"/>
              <xsl:for-each select="child::*">
                <xsl:sequence select="$citIndent"/>
                <xsl:copy-of select="."/>
              </xsl:for-each>
              <xsl:for-each select="$cit2/*[not(self::tei:quote)]">
                <xsl:variable name="currCit2Child" select="."/>
                <xsl:if test="not($cit1/*[deep-equal(., $currCit2Child)])">
                  <xsl:sequence select="$citIndent"/>
                  <xsl:copy-of select="$currCit2Child"/>
                </xsl:if>
              </xsl:for-each>
            </xsl:copy>
          </xsl:variable>
          
          <xsl:sequence select="$rep"/>
          
        </sqf:replace>
        
        <sqf:delete use-when="$canMerge" match="following-sibling::tei:cit[1]"/>
        
      </sqf:fix>
    </rule>
  </pattern>
Martin Holmes
University of Victoria
tavy
Posts: 388
Joined: Thu Jul 01, 2004 12:29 pm

Re: How to debug SQF?

Post by tavy »

Hello Martin,

Thanks for your feedback.
Unfortunately, we do not have support to debug SQF. I added an issue on our issue tracker to offer more feedback when a quick fix cannot be generated, or maybe offer a debug support.
I tried to reproduce the problem by creating a simple TEI file, but for my example the quick fix works fine. If you can send me a sample TEI file (maybe on our support email ) I can try to check why the quick fix is not generated.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
Martin Holmes
Posts: 10
Joined: Sat Mar 12, 2005 12:37 am

Re: How to debug SQF?

Post by Martin Holmes »

Thanks Octavian. I'll send a test file to the support email.

Cheers,
Martin
Martin Holmes
University of Victoria
Post Reply