Project

Profile

Help

Failed to compile stylesheet: Focus for child axis is absent with xslt3 while Saxon 9.9 and 10.0 and 10.1 Java compile and execute the code fine

Added by Martin Honnen about 1 month ago

In my fiddles for XQuery and XSLT using Saxon I like to provide users the option to use JSON as the context item/match selection instead of XML. As the command line interfaces of Saxon don't support that I have tried to write the following wrapper stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">
    
    <xsl:param name="method" as="xs:string" static="yes" select="'json'"/>
    
    <xsl:param name="xslt-uri" static="yes" as="xs:string?" select="'group-sales-sum-product.xsl'"/>
    
    <xsl:include _href="{$xslt-uri}"/>
    
    <xsl:param name="json-uri" as="xs:string?" select="'sales.json'"/>
    
    <xsl:param name="json-content" as="xs:string?" select="()"/>
    
    <xsl:variable name="input" as="item()" select="if (not(empty($json-uri))) then json-doc($json-uri) else parse-json($json-content)"/>
    
    <xsl:output _method="{$method}" indent="yes"/>
    
    <xsl:template name="xsl:initial-template">
        <xsl:apply-templates select="$input"/>
    </xsl:template>
    
</xsl:stylesheet>

I can run that stylesheet fine with Saxon 9.9 or 10.0 or 10.1 HE from the command line, using stylesheets like

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all">

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

  <xsl:template match=".">
    <xsl:map>
      <xsl:for-each-group select="?sales?*" group-by="?product">
        <xsl:sort select="current-grouping-key()"/>
        <xsl:map-entry key="current-grouping-key()" select="sum(current-group()?quantity)"/>
      </xsl:for-each-group>
    </xsl:map>
  </xsl:template>

</xsl:stylesheet>

as the "dynamic" include which then processes the provided JSON like

{
  "sales": [
    {
      "product": "broiler",
      "store number": 1,
      "quantity": 20
    },
    {
      "product": "toaster",
      "store number": 2,
      "quantity": 100
    },
    {
      "product": "toaster",
      "store number": 2,
      "quantity": 50
    },
    {
      "product": "toaster",
      "store number": 3,
      "quantity": 50
    },
    {
      "product": "blender",
      "store number": 3,
      "quantity": 100
    },
    {
      "product": "blender",
      "store number": 3,
      "quantity": 150
    },
    {
      "product": "socks",
      "store number": 1,
      "quantity": 500
    },
    {
      "product": "socks",
      "store number": 2,
      "quantity": 10
    },
    {
      "product": "shirt",
      "store number": 3,
      "quantity": 10
    }
  ]
}

just fine.

However, when I try to run Saxon-JS 2 using xslt3 that way, I get an error:

PS C:\Users\marti\SomePath\json-input> xslt3 -t -it -xsl:include-wrapper-for-json-input.xsl
Saxon-JS 2.0 from Saxonica
Node.js version v12.18.0
Compiling stylesheet C:\Users\marti\SomePath\json-input\include-wrapper-for-json-input.xsl
Failed to compile stylesheet: Focus for child axis is absent
Error XPDY0002 at static.xsl#392
    Failed to compile stylesheet
Error XPDY0002 at static.xsl#392
    Focus for child axis is absent

Replies (2)

RE: Failed to compile stylesheet: Focus for child axis is absent with xslt3 while Saxon 9.9 and 10.0 and 10.1 Java compile and execute the code fine - Added by Michael Kay about 1 month ago

Thanks for reporting it.

static.xsl is the module of the XX compiler that handles static variables, shadow attributes, etc, and the code at #392 is the call on xsl:evaluate that evaluates the @select attribute of a static variable or parameter. The failure is then somewhere within the XPath parser. I've no idea why it's trying to use the child axis!

    (1-2/2)

    Please register to reply