Insert outline numbering into Schematron files

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>

Linkbacks

Use the following URL for manually sending trackbacks: http://rigo.info/lib/plugins/linkback/exe/trackback.php/en:blog:insert_outline_numbering_into_schematron_files
en/blog/insert_outline_numbering_into_schematron_files.txt · Utolsó módosítás: 2009-05-18 00:00 (külső szerkesztés)
CC Attribution-Noncommercial-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0