Project

Profile

Help

Bug #3243

closed

Variables incorrectly in-lined into xsl:on-completion

Added by John Lumley almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XSLT conformance
Sprint/Milestone:
-
Start date:
2017-06-01
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.7, trunk
Fix Committed on Branch:
9.7, trunk
Fixed in Maintenance Release:
Platforms:

Description

For the code

<xsl:variable name="me">
     <xsl:copy-of select="."/>
</xsl:variable>
<xsl:iterate select="*">
     <xsl:on-completion>
         <xsl:sequence select="$me"/>
     </xsl:on-completion>
     <xsl:sequence select="."/>
</xsl:iterate>

Saxon incorrectly in-lines the variable into the @on-completion@, where on execution the context item is absent and hence an error is raised. The export is:

<iterate role="action" ns="xsl=~ xs=~ math=http://www.w3.org/2005/xpath-functions/math" line="21">
     <axis role="select" name="child" nodeTest="element()" jsTest="return item.nodeType===1;"/>
     <params role="params"/>
     <doc role="on-completion" line="19" validation="preserve">
      <copyOf flags="vsc">
       <dot type="element(Q{}out)"/>
      </copyOf>
     </doc>
     <dot role="action" line="25" type="element()"/>
</iterate>

As a workround, a reference through xsl:message can suppress the inlining.

Actions #1

Updated by Michael Kay almost 7 years ago

I'm not getting an error here, I'm getting $me treated as a reference to the outer context item. That's apparently because on Saxon/J the xsl:on-completion is being evaluated in the outer context, without setting the focus to absent.

The reason the variable is being inlined is that there's only one reference to it, and the reference isn't in a loop. Saxon is wrongly assuming that the focus is only changed by looping constructs. (There's one other notable example of a construct that changes the focus but doesn't loop, specifically xsl:copy, and we handle this by injecting an "for-each select="." to make it appear to loop).

Actions #2

Updated by Michael Kay almost 7 years ago

  • Category set to XSLT conformance
  • Status changed from New to Resolved
  • Applies to branch 9.7, trunk added
  • Applies to branch deleted (9.8)
  • Fix Committed on Branch 9.7, trunk added

Added test cases iterate-037 and iterate-038.

It seems that on both 9.7 and 9.8, the "absent context item" error is detected with bytecode enabled, but not when interpreted. The bytecode version is executing xsl:completion with the same context object as the loop body, and it reports "context item absent" because the iterator is exhausted. It feels slightly "dirty" allowing a call on iter.next() after the iterator is exhausted, but it should be OK so I will leave it.

Actions #3

Updated by O'Neil Delpratt almost 7 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 9.7.0.19 added

Bug fix applied in the 9.7.0.19 maintenance release.

Please register to edit this issue

Also available in: Atom PDF