Project

Profile

Help

Bug #5037

closed

empty AVT causes error "Cannot read property 'value' of null"

Added by Martin Honnen almost 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
XSLT Conformance
Sprint/Milestone:
-
Start date:
2021-07-06
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
2
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

The spec https://www.w3.org/TR/xslt-30/#value-templates allows AVTs to be empty: "A variable part consists of an optional XPath expression enclosed in curly brackets ({}): more specifically, a string conforming to the XPath production Expr?.", saying that "The fact that the expression is optional means that the string contained between the curly brackets may be zero-length, may comprise whitespace only, or may contain XPath comments. The effective value in this case is a zero-length string, which is equivalent to omitting the variable part entirely, together with its curly-bracket delimiters.".

However, with Saxon-JS 2.2, both in the browser or on Node.js, the code

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/" name="xsl:initial-template">
    <test>
      <xsl:variable name="element-name" select="'foo'"/>
      <xsl:element name="{$element-name}" namespace="{}">test</xsl:element>
    </test>
    <xsl:comment>Run with <xsl:value-of select="system-property('xsl:product-name')"/>; <xsl:value-of select="system-property('xsl:product-version')"/></xsl:comment>
  </xsl:template>

</xsl:stylesheet>

gives an error "Cannot read property 'value' of null".

The code runs fine with Saxon Java, I think Saxon-JS has a bug here.

Actions #1

Updated by Martynas Jusevicius almost 3 years ago

What version of Node.js? I had a somewhat similar issue which was due to an old version of it: https://saxonica.plan.io/issues/4957

Actions #2

Updated by Martin Honnen almost 3 years ago

Node 14, I think. But happens in the browser as well.

Actions #3

Updated by Debbie Lockett almost 3 years ago

  • Status changed from New to In Progress

Thanks for providing the repro. Indeed this is a problem which only arises with an XX-compiled stylesheet (i.e. exported with Saxon-JS on Node.js, rather than with Saxon-EE). The stylesheet XX-compiles to SEF, but then there is a runtime failure, which results in the error "Transformation failure: TypeError: Cannot read property 'value' of null".

Specifically, the error is thrown while processing the compElem expression which contains

{
  "N": "empty",
  "sType": "0 ",
   "role": "namespace"
},

because it is (wrongly) assumed that the result of this namespace expression is non-empty.

I will add a test to the XSLT3 test suite. Note that there are other tests for empty AVTs (e.g. avt-2102 has an empty AVT on a literal result element, and this test passes), but no test for this specific case (empty AVT for the namespace attribute of xsl:element).

Actions #4

Updated by Debbie Lockett almost 3 years ago

  • Status changed from In Progress to Resolved
  • Fix Committed on JS Branch 2 added

XSLT3 test avt-2103 added, and fix committed in computedQNameEvaluator in Push.js.

Actions #5

Updated by Debbie Lockett over 2 years ago

  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 2.3

Bug fix applied in the Saxon-JS 2.3 maintenance release.

Actions #6

Updated by Debbie Lockett over 2 years ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF Tracking page