Project

Profile

Help

XSLT function not compiling with SaxonC-HE 12.0 (Python)

Added by Ulrich Belz over 1 year ago

As soon as I paste the the definition of the function my:scan into the stylesheet, it does not compile ("Errors were reported during stylesheet compilation"). Without it, everything works fine (both compilation and transformation). What's wrong with it?

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:xs="http://www.w3.org/2001/XMLSchema"
                              xmlns:pt="http://www.fnfr.com/schemas/parameterTree"
                              xmlns:my="http://mycompany.com/mynamespace"
                              exclude-result-prefixes="my">

<xsl:output omit-xml-declaration="yes" method="text" indent="no" encoding="UTF-8"/>



<xsl:function name="my:scan" as="xs:integer*">
  <xsl:param name="input" as="item()*"/>
  <xsl:param name="accumulator" as="xs:integer" select="0"/>

  <xsl:choose>
    <xsl:when test="empty($input)">   
      <xsl:sequence select="$accumulator"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="nextaccumulator" as="xs:integer" select="$accumulator + xs:integer($input[1])"/>
      <xsl:sequence select="($accumulator, my:scan(tail($input), $nextaccumulator))"/>
    </xsl:otherwise>
  </xsl:choose>
  
</xsl:function>

...

Replies (9)

Please register to reply

XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by John Lumley over 1 year ago

On 10/03/2023 16:28, Saxonica Developer Community wrote:

RE: XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by Michael Kay over 1 year ago

Paste this into Oxygen, with an xsl:stylesheet end tag, and you get the error message:

"The select attribute is not permitted on a function parameter".

So your first problem is that you're not seeing the error messages. That's probably because they are going somewhere where you aren't looking. Check how you are compiling the stylesheet and where you are sending the errors.

The next problem is trivial, you can't (in XSLT 3.0) define a default value for function parameters. If you're trying to use the experimental feature in XSLT 4.0 which does allow this, then you need to enable XSLT 4.0 extensions.

RE: XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by Martin Honnen over 1 year ago

Given that you use HE you are not likely experimenting with XSLT 4 features so I guess you want e.g.

<xsl:function name="my:scan" as="xs:integer*">
  <xsl:param name="input" as="item()*"/>
  <xsl:sequence select="my:scan($input, 0)"/>
</xsl:function>

<xsl:function name="my:scan" as="xs:integer*">
  <xsl:param name="input" as="item()*"/>
  <xsl:param name="accumulator" as="xs:integer"/>

  <xsl:choose>
    <xsl:when test="empty($input)">   
      <xsl:sequence select="$accumulator"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="nextaccumulator" as="xs:integer" select="$accumulator + xs:integer($input[1])"/>
      <xsl:sequence select="($accumulator, my:scan(tail($input), $nextaccumulator))"/>
    </xsl:otherwise>
  </xsl:choose>
  
</xsl:function>

RE: XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by Ulrich Belz over 1 year ago

Thank you very much for the quick response. Yes, looks like using the experimental feature in XSLT 4.0 is not an option for me, as XSLT 4.0 requires Saxon-PE or higher, acc. to the docs Thanks for pointing to the select attribute of xsl:param. Indeed, that caused the problem, and in my case I do not really need it. (On the other hand, on the xsl:param refererence page, I could not find limitations regarding the select attribute ...).

Good question, where do the error messages go? There is nothing special I do. I am running a Python script from a cli or from within Eclipse under Windows, calling compilation and transformation like this:

  def transform(self, sourceFilname, destFilename, stylesheetFilename):
    
    with PySaxonProcessor(license=False) as proc:
      xsltproc = proc.new_xslt30_processor()
      

      doc = proc.parse_xml(xml_file_name=sourceFilname)
    
      executable = xsltproc.compile_stylesheet(stylesheet_file=stylesheetFilename, lang='3.0')
      
#      print(xsltproc.__dir__())
      
      if xsltproc.exception_occurred:
        print(xsltproc.error_code)
        print(xsltproc.error_message) 
      
      executable.transform_to_file(output_file=destFilename, xdm_node=doc)

In both cases, while executable.transform_to_file prints out error messages (if any), xsltproc.compile_stylesheet only provides the xsltproc.error_message, no further error printouts.

RE: XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by Martin Honnen over 1 year ago

I can confirm that your Python code doesn't output more than the "Errors were reported during stylesheet compilation" with 12.0 HE. Let's wait whether Saxonica's O'Neil shows up to tell whether the upcoming 12.1 provides better error diagnostics.

RE: XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by O'Neil Delpratt over 1 year ago

Hi thanks for reporting this issue. I will investigate it further and report back.

RE: XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by O'Neil Delpratt over 1 year ago

The C++ SaxonApiException class has a getCombinedStaticErrorMessages() method for reporting errors found at the compile stage, but currently we are not not passing these messages to the Python API.

This is a bug and I have created the following bug issue to track progress: #5918

RE: XSLT function not compiling with SaxonC-HE 12.0 (Python) - Added by O'Neil Delpratt over 1 year ago

I have applied a fix to the bug issue #5918. We now capture the exceptions handling in the compile stage. This fix will be available in the SaxonC 12.1 maintenance release.

    (1-9/9)

    Please register to reply