Log in

HCMC Journal

Work on diagnostics and Schematron

to : Martin Holmes
Minutes: 195

Worked with SK on adding some new diagnostics, and preparing for some Schematron to tame variable sense structures; having used XPath to identify problem cases, which were then solved, I was able to add Schematron to catch future instances.

In a follow-up bit of work, we devised something slightly cunning which is worth documenting. This works on any XSLT file which is running on itself (it is both the source and the XSLT).

        <!-- Set this param to limit the run to a comma-separated list of template names. -->
        <xsl:param name="runOnly" as="xs:string" select="''"/>
        <xsl:variable name="docRoot" as="document-node()" select="/"/>
        
        ...
        
        <-- Templates configured to look like this: -->
        
        <xsl:template name="stemsWithHyphs" match="xsl:template[@name='stemsWithHyphs']">
          ...
        </xsl:template>
        
        ...
        
        <-- Then the meat of it: -->
        
        <xsl:choose>
        
            <xsl:when test="$runOnly = ''">
              <-- Do the whole set of regular stuff... -->
            </xsl:when>
            
            <xsl:otherwise>
                <div id="selectedDiagnostics">
                    <h2>Selected diagnostics</h2>
                    <xsl:for-each select="tokenize($runOnly, ',')">
                        <xsl:variable name="templateName" as="xs:string" select="."/>
                        <xsl:apply-templates select="$docRoot//xsl:template[@name = $templateName]"/>
                    </xsl:for-each>
                </div>
            </xsl:otherwise>
        </xsl:choose>
    

This enables us to run only a subset of diagnostics very quickly, without having to comment out the others temporarily, which is time-consuming and error-prone.