title: Uncaught TypeError: Cannot read properties of null (reading 'hashCode') [SaxonJS]
body: <p>I'm getting this error in Chrome console:</p>
  <p><a href="https://i.stack.imgur.com/pzvOS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pzvOS.png" alt="enter image description here" /></a></p>
  <p>Seems to be a problem with XSLT or SEF as other SEF works.
  I complie SEF with the <code>xslt3</code> tool on Node.js version v14.17.3.</p>
  <p>I can run the XSLT with Saxon 9.8.12-EE in oXygen with no problem.</p>
  <p>Maybe the problem with maps, <code>xsl:include</code> or <code>xsl:import</code>?</p>
  <p>Here is the XSLT code:</p>
  <pre class="lang-xml prettyprint-override"><code>
  &lt;stylesheet exclude-result-prefixes=&quot;xs xd dme functx dita mei map array&quot; extension-element-prefixes=&quot;ixsl&quot; version=&quot;3.0&quot; xmlns=&quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns:array=&quot;http://www.w3.org/2005/xpath-functions/array&quot; xmlns:dita=&quot;http://dita-ot.sourceforge.net&quot; xmlns:dme=&quot;http://www.mozarteum.at/ns/dme&quot; xmlns:functx=&quot;http://www.functx.com&quot; xmlns:ixsl=&quot;http://saxonica.com/ns/interactiveXSLT&quot; xmlns:map=&quot;http://www.w3.org/2005/xpath-functions/map&quot; xmlns:mei=&quot;http://www.music-encoding.org/ns/mei&quot; xmlns:xd=&quot;http://www.oxygenxml.com/ns/doc/xsl&quot; xmlns:xi=&quot;http://www.w3.org/2001/XInclude&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; xpath-default-namespace=&quot;http://www.music-encoding.org/ns/mei&quot;&gt;
  
  
    &lt;xi:include href=&quot;docs.xsl&quot; xpointer=&quot;element(/1/1)&quot;/&gt;
    &lt;import href=&quot;changeLog.xsl&quot;/&gt;
  
  
  
    &lt;!--This parameter is a needed for XSpec. Cf. https://github.com/xspec/xspec/wiki/Global-Context-Item--&gt;
    &lt;param name=&quot;global-context-item&quot; select=&quot;.&quot;/&gt;
  
    &lt;param name=&quot;source&quot;/&gt;
  
  
    &lt;include href=&quot;../modules/identity-transform.xsl&quot;/&gt;
  
  
    &lt;xd:doc&gt;
      &lt;xd:desc&gt;
        &lt;xd:p&gt;Replace current scoreDef with the alternative. Note that this should be defined in the following-sibling &amp;lt;choice&amp;gt;.&lt;/xd:p&gt;
      &lt;/xd:desc&gt;
    &lt;/xd:doc&gt;
    &lt;template match=&quot;scoreDef[not(@corresp = concat('#', $source))]&quot;&gt;
      &lt;copy-of select=&quot;following-sibling::choice[@type = 'scoring']/*[@corresp = concat('#', $source)]/scoreDef&quot;/&gt;
  
    &lt;/template&gt;
  
    &lt;xd:doc&gt;
      &lt;xd:desc/&gt;
    &lt;/xd:doc&gt;
    &lt;template match=&quot;choice[@type = 'scoring']&quot;/&gt;
  
    &lt;xd:doc&gt;
      &lt;xd:desc&gt;
        &lt;xd:p&gt;Map staffDef@n of the new scoreDef and @dme.parts.&lt;/xd:p&gt;
      &lt;/xd:desc&gt;
    &lt;/xd:doc&gt;
    &lt;variable as=&quot;map(xs:string, item())*&quot; name=&quot;map_staves_order&quot;&gt;
      &lt;for-each select=&quot;$global-context-item//choice[@type = 'scoring']/*[@corresp = concat('#', $source)]/scoreDef&quot;&gt;
        &lt;map&gt;
          &lt;for-each select=&quot;descendant::staffDef&quot;&gt;
            &lt;map-entry key=&quot;string(@n)&quot; select=&quot;@dme.parts&quot;/&gt;
          &lt;/for-each&gt;
        &lt;/map&gt;
      &lt;/for-each&gt;
    &lt;/variable&gt;
  
    &lt;xd:doc&gt;
      &lt;xd:desc&gt;
        &lt;xd:p&gt;Get the maximum number of staves.&lt;/xd:p&gt;
      &lt;/xd:desc&gt;
    &lt;/xd:doc&gt;
    &lt;variable as=&quot;xs:integer&quot; name=&quot;count_staves&quot; select=&quot;
        max(for $a in map:keys($map_staves_order)
        return
          if (matches($a, '\d')) then
            xs:integer($a)
          else
            ())&quot;/&gt;
  
  
    &lt;xd:doc&gt;
      &lt;xd:desc&gt;
        &lt;xd:p&gt;Key: old @n.&lt;/xd:p&gt;
        &lt;xd:p&gt;Value: new @n&lt;/xd:p&gt;
      &lt;/xd:desc&gt;
    &lt;/xd:doc&gt;
    &lt;variable as=&quot;map(xs:string, xs:string)*&quot; name=&quot;map_new_old_staves&quot;&gt;
      &lt;map&gt;
        &lt;for-each select=&quot;map:keys($map_staves_order)&quot;&gt;
          &lt;variable name=&quot;current_key&quot; select=&quot;.&quot;/&gt;
          &lt;map-entry key=&quot;$global-context-item//measure[@n = 1]/staff[@dme.parts = map:get($map_staves_order, $current_key)]/@n/string()&quot; select=&quot;.&quot;/&gt;
        &lt;/for-each&gt;
      &lt;/map&gt;
  
    &lt;/variable&gt;
  
  
  
    &lt;xd:doc&gt;
      &lt;xd:desc&gt;
        &lt;xd:p&gt;Copies elements before first staff without changes, e.g. &amp;lt;tempo&amp;gt;&lt;/xd:p&gt;
        &lt;xd:p&gt;Copies staves accordingly to the new score order. Changes the @n-attribute accordingly&lt;/xd:p&gt;
        &lt;xd:p&gt;Copies ControlEvents and updates the @staff attribute if neccessary.&lt;/xd:p&gt;
      &lt;/xd:desc&gt;
    &lt;/xd:doc&gt;
    &lt;template match=&quot;measure&quot;&gt;
      &lt;copy&gt;
        &lt;apply-templates select=&quot;@*&quot;/&gt;
        &lt;apply-templates select=&quot;child::staff[1]/preceding-sibling::*&quot;/&gt;
  
        &lt;variable as=&quot;element()&quot; name=&quot;currentMeasure&quot; select=&quot;.&quot;/&gt;
        &lt;for-each select=&quot;1 to $count_staves&quot;&gt;
          &lt;variable as=&quot;xs:string&quot; name=&quot;currentItem&quot; select=&quot;string()&quot;/&gt;
          &lt;for-each select=&quot;$currentMeasure/child::staff[map:get($map_staves_order, $currentItem) = @dme.parts]&quot;&gt;
            &lt;copy&gt;
              &lt;attribute name=&quot;n&quot; select=&quot;$currentItem&quot;/&gt;
              &lt;apply-templates select=&quot;(@* except @n) | node()&quot;/&gt;
            &lt;/copy&gt;
          &lt;/for-each&gt;
        &lt;/for-each&gt;
  
        &lt;call-template name=&quot;update_staff_controlEvents&quot;&gt;
          &lt;with-param name=&quot;elements&quot; select=&quot;child::staff[last()]/following-sibling::*&quot;/&gt;
        &lt;/call-template&gt;
      &lt;/copy&gt;
    &lt;/template&gt;
  
  
  
    &lt;xd:doc&gt;
      &lt;xd:desc&gt;
        &lt;xd:p&gt;Receives one or more elements (controlEvents) and updates their @staff according to the $map_new_old_staves variable.&lt;/xd:p&gt;
        &lt;xd:p&gt;Recursive template&lt;/xd:p&gt;
      &lt;/xd:desc&gt;
      &lt;xd:param name=&quot;elements&quot;/&gt;
    &lt;/xd:doc&gt;
    &lt;template name=&quot;update_staff_controlEvents&quot;&gt;
      &lt;param name=&quot;elements&quot;/&gt;
  
      &lt;for-each select=&quot;$elements&quot;&gt;
        &lt;choose&gt;
          &lt;when test=&quot;@staff&quot;&gt;
            &lt;copy&gt;
              &lt;attribute name=&quot;staff&quot; select=&quot;map:get($map_new_old_staves, @staff)&quot;/&gt;
              &lt;apply-templates select=&quot;@* except @staff&quot;/&gt;
              &lt;if test=&quot;node()&quot;&gt;
                &lt;call-template name=&quot;update_staff_controlEvents&quot;&gt;
                  &lt;with-param name=&quot;elements&quot; select=&quot;node()&quot;/&gt;
                &lt;/call-template&gt;
              &lt;/if&gt;
            &lt;/copy&gt;
          &lt;/when&gt;
          &lt;otherwise&gt;
            &lt;copy&gt;
              &lt;apply-templates select=&quot;@*&quot;/&gt;
              &lt;if test=&quot;node()&quot;&gt;
                &lt;call-template name=&quot;update_staff_controlEvents&quot;&gt;
                  &lt;with-param name=&quot;elements&quot; select=&quot;node()&quot;/&gt;
                &lt;/call-template&gt;
              &lt;/if&gt;
            &lt;/copy&gt;
          &lt;/otherwise&gt;
        &lt;/choose&gt;
      &lt;/for-each&gt;
    &lt;/template&gt;
  
  &lt;/stylesheet&gt;
  </code></pre>
  <p>JS which I run on Console:</p>
  <pre class="lang-js prettyprint-override"><code>
  
  var options = {
        stylesheetLocation: &quot;./assets/xsl/origScoring.sef.json&quot;,
           sourceText: xmlString,    
             stylesheetParams: {&quot;source&quot;: &quot;source_A&quot;},
           destination: &quot;document&quot;
  }
  
  var result = SaxonJS.transform(options);
  result.principalResult
  </code></pre>