Project

Profile

Help

Error during xslt execution in Saxon HE 9.8.0-14

Added by Vladimir Nesterovsky over 5 years ago

I get an error:

Error at char 18 in xsl:sequence/@select on line 32 column 60 of test.xslt:
  FORG0005: A sequence of more than one item is not allowed as the first argument of
  fn:exactly-one() (<a/>, <b/>) 
  at t:f() (...)
A sequence of more than one item is not allowed as the first argument of fn:exactly-one() (<a/>, <b/>) 

for a following stylesheet:

<xsl:stylesheet version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  xmlns:t="t">
  
  <xsl:param name="items" as="element()*">
    <a pid="1"/>
    <b pid="1"/>
    <c pid="2"/>
    <d pid="2"/>
    <e pid="2"/>
  </xsl:param>
  
  <xsl:template match="/">
    <xsl:message select="t:f($items)"/>
  </xsl:template>
  
  <xsl:function name="t:f" as="xs:string*">
    <xsl:param name="items" as="element()*"/>

    <xsl:variable name="info" as="map(xs:string, element()+)" select="
      map:merge
      (
        $items!map { xs:string(@pid): . },
        map { 'duplicates': 'combine' }
      )"/>

    <xsl:variable name="keys" as="xs:string*" select="$info=>map:keys()"/>
      
    <xsl:sequence select="$keys!exactly-one($info(.)[1])"/>
  </xsl:function>

</xsl:stylesheet>

Input xml is anything.

In my opinion there should not be any error.


Replies (2)

RE: Error during xslt execution in Saxon HE 9.8.0-14 - Added by Vladimir Nesterovsky over 5 years ago

I want to add that following does not produce an error:

<xsl:sequence select="$keys!exactly-one($info(.)=>subsequence(1, 1))"/>

Neither error happens if to put logic directly into xsl:template.

RE: Error during xslt execution in Saxon HE 9.8.0-14 - Added by Michael Kay over 5 years ago

I have raised this at

https://saxonica.plan.io/issues/3980

The problem is caused by an incorrect type inference. This causes the compiler to assume that map:merge() will always return a map of type map(xs:string, element()), which in turn results in the predicate [1] being dropped as redundant, which then leads to the dynamic error from the call on exactly-one().

    (1-2/2)

    Please register to reply