I was requested to insert outline numbering into a Schematron rule file for debug purposes. Here is the resulting XSLT file:
<?xml version="1.0"?> <!-- Insert outline numbering into Schematron files - Ernő Rigó <erno@rigo.info> --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sch="http://www.ascc.net/xml/schematron" schemaVersion="1.0" > <xsl:template match="sch:pattern"> <xsl:variable name="counter"> <xsl:value-of select="count(preceding-sibling::sch:pattern) + 1"/> </xsl:variable> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:comment>PatternNUM:<xsl:number value="$counter" format="001" /></xsl:comment> <xsl:apply-templates> <xsl:with-param name="patternnum"> <xsl:number value="$counter" format="001" /> </xsl:with-param> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="sch:rule"> <xsl:param name="patternnum" /> <xsl:variable name="counter"> <xsl:value-of select="count(preceding-sibling::sch:rule) + 1"/> </xsl:variable> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:comment>RuleNUM:<xsl:value-of select="$patternnum" />.<xsl:number value="$counter" format="001" /></xsl:comment> <xsl:apply-templates> <xsl:with-param name="patternnum"> <xsl:number value="$patternnum" format="001" /> </xsl:with-param> <xsl:with-param name="rulenum"> <xsl:number value="$counter" format="001" /> </xsl:with-param> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="sch:assert"> <xsl:param name="patternnum" /> <xsl:param name="rulenum" /> <xsl:variable name="counter"> <xsl:value-of select="count(preceding-sibling::sch:assert) + 1"/> </xsl:variable> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:variable name="myid"> <xsl:value-of select="$patternnum" />.<xsl:value-of select="$rulenum" />.<xsl:number value="$counter" format="001" /> </xsl:variable> <xsl:comment>AssertNUM:<xsl:value-of select="$myid" /></xsl:comment> <xsl:apply-templates />(AssertNUM:<xsl:value-of select="$myid" />) </xsl:copy> </xsl:template> <xsl:template match="sch:report"> <xsl:param name="patternnum" /> <xsl:param name="rulenum" /> <xsl:variable name="counter"> <xsl:value-of select="count(preceding-sibling::sch:report) + 1"/> </xsl:variable> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:variable name="myid"> <xsl:value-of select="$patternnum" />.<xsl:value-of select="$rulenum" />.<xsl:number value="$counter" format="001" /> </xsl:variable> <xsl:comment>ReportNUM:<xsl:value-of select="$myid" /></xsl:comment> <xsl:apply-templates />(ReportNUM:<xsl:value-of select="$myid" />) </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>