Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.

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

Description

@dmj

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDescription of a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions