Project

Profile

Help

Bug #5337

closed

callTemplateReturningValue(null) with PHP does not call the template named xsl:initial-template but rather gives error "java.lang.IllegalArgumentException: Supplied Clark name is null or empty"

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

Status:
Closed
Priority:
Normal
Category:
PHP API
Start date:
2022-02-18
Due date:
% Done:

100%

Estimated time:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
11.2
Fixed in version:
11.3
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:

Description

The documentation for the Saxon 11 (testing with 11.2 HE now) PHP API and callTemplateReturningValue says:

Invoke a transformation by calling a named template, and return the result as an XdmValue. If the $templateName argument is null then the xsl:initial-template is used

However, when I try to pass null as the method value, Saxon gives an error:

Error found in calltemplateReturningValue
Exception in thread "main" java.lang.IllegalArgumentException: Supplied Clark name is null or empty
        at net.sf.saxon.s9api.QName.fromClarkName(Unknown Source)
        at net.sf.saxon.option.cpp.Xslt30Processor.callTemplateReturningValue(Unknown Source)

Test code:

<?php
  $saxonProc = new Saxon\SaxonProcessor();
  $transformer = $saxonProc->newXslt30Processor();
  $executable = $transformer->compileFromString("<xsl:stylesheet version='3.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' expand-text='yes'>\n<xsl:template name='xsl:initial-template'><test>{current-dateTime()} : {system-property('xsl:product-name')} {system-property('xsl:product-version')}</test></xsl:template>\n</xsl:stylesheet>");
  $root = $executable->callTemplateReturningValue(null);
  $node = $root->getHead()->getNodeValue();
  print($node);
?>

What works for me to have xsl:initial-template called is to pass no argument with e.g. $root = $executable->callTemplateReturningValue();. If that is the intended and only shortcut to have xsl:initial-template called, then the documentation is misleading.

Actions #1

Updated by O'Neil Delpratt almost 3 years ago

  • Status changed from New to In Progress

Firstly, the NULL should be accepted therefore this looks like a bug issue. Secondly, the documentation needs updating to accept zero argument too for both C++ and PHP.

I have reproduced the problem, which does puzzle me because the zero argument does get converted internally to NULL as the argument in this method in C++. My suspicion is we are getting an empty string at some point in the process.

Actions #2

Updated by O'Neil Delpratt almost 3 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100

Bug found in the PHP extension code. The zend_parse_parameter function handles the NULL strings as an empty string in C (with possible NUL-bytes). Bug fix applied to check against the length of the string when passing templateName to the C++ API.

Actions #3

Updated by O'Neil Delpratt over 2 years ago

  • Status changed from Resolved to Closed
  • Fixed in version set to 11.3

Bug fix applied in the SaxonC 11.3 maintenance release.

Please register to edit this issue

Also available in: Atom PDF