Schematron / schematron

Schematron "skeleton" - XSLT implementation
MIT License
93 stars 45 forks source link

Creates invalid stylesheet if two patterns bind variables with the same name #76

Open dmj opened 5 years ago

dmj commented 5 years ago

Given the following Schematron:

<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
  <pattern id="pattern-1">
    <let name="variable" value="'in-pattern-1'"/>
    <rule context="*">
      <assert test="true()"/>
    </rule>
  </pattern>
  <pattern id="pattern-2">
    <let name="variable" value="'in-pattern-2'"/>
    <rule context="*">
      <assert test="true()"/>
    </rule>
  </pattern>
</schema>

The Skeleton implementation creates the following XSLT 2.0 stylesheet with two global variables with the same name:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:saxon="http://saxon.sf.net/"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:schold="http://www.ascc.net/xml/schematron"
                xmlns:iso="http://purl.oclc.org/dsdl/schematron"
                xmlns:xhtml="http://www.w3.org/1999/xhtml"
                version="2.0">

  <!-- ... -->

  <!--SCHEMATRON PATTERNS-->

  <!--PATTERN pattern-1-->
  <xsl:variable name="variable" select="'in-pattern-1'"/>

  <!--RULE -->

  <xsl:template match="*" priority="1000" mode="M0">
    <!-- ... -->
  </xsl:template>

  <!-- ... -->

  <!--PATTERN pattern-2-->
  <xsl:variable name="variable" select="'in-pattern-2'"/>

  <!--RULE -->
  <xsl:template match="*" priority="1000" mode="M1">
    <!-- ... -->
  </xsl:template>

  <!-- ... -->

</xsl:stylesheet>

Section 9.5 (Global Variables and Parameters) of the XSLT 2.0 specification reads:

If a stylesheet contains more than one binding for a global variable of a particular name, then the binding with the highest import precedence is used.

[ERR XTSE0630] It is a static error if a stylesheet contains more than one binding of a global variable with the same name and same import precedence, unless it also contains another binding with the same name and higher import precedence.

Running the stylesheet with Saxon rightfully results in XTSE0630:

Static error at xsl:variable on line 198 column 59 of schema.sch-compiled.xsl:
  XTSE0630: Duplicate global variable/parameter declaration (see line 224 of
  file:///D:/Home/tmp/report/schema.sch-compiled.xsl)

To reproduce run https://github.com/dmj/schxslt/blob/master/tests/impl/let/let-scope-02.xspec with the skeleton implementation.