Bug #3326
closedXTDE1061: There is no current group in Saxon-HE-9.8.0-2
100%
Updated by Michael Kay over 7 years ago
Created W3C XSLT30 test case for-each-group-085
Updated by Michael Kay over 7 years ago
Here's the -explain output:
OPT : At line 6 of file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl
OPT : Rewriting numeric filter expression with constant subscript
OPT : Expression after rewrite: child::element()[2]
OPT : At line 6 of file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl
OPT : Rewrote Filter Expression as:
OPT : Expression after rewrite: child::element()[2]
OPT : At line 12 of file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl
OPT : Inlined references to $t
OPT : Expression after rewrite: let $o := ForEachGroup(<t {FixedAttribute("T")}/>, let $g := one-or-more((current-group()) treat as element()) return ($g[(data(attribute::attribute(Q{}n))) = (data($c/attribute::attribute(Q{}n)))]), data(attribute::attribute(Q{}n)), "http://www.w3.org/2005/xpath-functions/collation/codepoint") return (ApplyTemplates(child::node(), $o))
OPT : At line 21 of file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl
OPT : Inlined references to $o
OPT : Expression after rewrite: ApplyTemplates(child::node(), ForEachGroup(<t {FixedAttribute("T")}/>, let $g := one-or-more((current-group()) treat as element()) return ($g[(data(attribute::attribute(Q{}n))) = (data($c/attribute::attribute(Q{}n)))]), data(attribute::attribute(Q{}n)), "http://www.w3.org/2005/xpath-functions/collation/codepoint"))
OPT : At line 15 of file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl
OPT : Lifted (let $g := ...) above (xsl:apply-templates) on line 21
OPT : Expression after rewrite: let $Q{http://saxon.sf.net/generated-variable}v0 := let $g := (one-or-more(current-group())) treat as element() return ($g[data(@n) = (data($c/attribute::attribute(Q{}n)))]) return (ApplyTemplates(child::node(), ForEachGroup(<t {FixedAttribute("T")}/>, $Q{http://saxon.sf.net/generated-variable}v0, data(@n), "http://www.w3.org/2005/xpath-functions/collation/codepoint")))
OPT : At line 17 of file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl
OPT : Lifted ($c / @n) above (let $vv:v0 := ...) on line 15
OPT : Expression after rewrite: let $Q{http://saxon.sf.net/generated-variable}v1 := data($c/attribute::attribute(Q{}n)) return (let $Q{http://saxon.sf.net/generated-variable}v0 := let $g := (one-or-more(current-group())) treat as element() return ($g[data(@n) = $Q{http://saxon.sf.net/generated-variable}v1]) return (ApplyTemplates(child::node(), ForEachGroup(<t {FixedAttribute("T")}/>, $Q{http://saxon.sf.net/generated-variable}v0, data(@n), "http://www.w3.org/2005/xpath-functions/collation/codepoint"))))
Stylesheet compilation time: 522.359446ms
<stylesheet xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalVariables/>
<mode onNo="TC" flags="dW" patternSlots="0">
<ruleSet type="namedElements">
<ruleChain key="c">
<templateRule prec="0"
prio="0.5"
seq="0"
rank="1"
minImp="0"
slots="4"
flags="s"
line="5"
module="file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl">
<p.withUpper role="match" axis="parent" upFirst="false">
<p.nodeTest test="element(Q{}c)"/>
<p.nodeTest test="document-node()"/>
</p.withUpper>
<let role="action"
baseUri="file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl"
ns="xsl=~ xs=~"
line="6"
var="c"
as="element()?"
slot="0"
eval="7">
<subscript>
<axis name="child" nodeTest="element()"/>
<int val="2"/>
</subscript>
<let xmlns:vv="http://saxon.sf.net/generated-variable"
line="17"
var="vv:v1"
as="xs:untypedAtomic?"
slot="1"
eval="13">
<data>
<slash simple="1">
<varRef name="c" slot="0"/>
<axis name="attribute" nodeTest="attribute(Q{}n)"/>
</slash>
</data>
<let line="15" var="vv:v0" as="element()*" slot="2" eval="4">
<let var="g"
as="(element() intersect element(Q{}t, Q{http://www.w3.org/2001/XMLSchema}untyped))+"
slot="3"
eval="8">
<treat as="element()" diag="3|0|XTTE0570|g">
<check card="+" diag="3|0|XTTE0570|g">
<currentGroup/>
</check>
</treat>
<filter line="17" flags="b">
<varRef name="g" slot="3"/>
<gc op="=" card="1:1" comp="CCC">
<attVal name="Q{}n" chk="0"/>
<varRef name="vv:v1" slot="1"/>
</gc>
</filter>
</let>
<applyT line="21" flags="i" bSlot="0">
<axis role="select" name="child" nodeTest="node()"/>
<withParam name="o" flags="t" as="element()*">
<forEachGroup line="9" algorithm="by">
<elem role="select" name="t" namespaces="xs">
<att name="n" flags="l">
<str val="T"/>
</att>
</elem>
<attVal role="key" line="13" name="Q{}n" chk="0"/>
<str role="collation"
val="http://www.w3.org/2005/xpath-functions/collation/codepoint"/>
<varRef role="content" line="15" name="vv:v0" slot="2"/>
</forEachGroup>
</withParam>
</applyT>
</let>
</let>
</let>
</templateRule>
</ruleChain>
<ruleChain key="t">
<templateRule prec="0"
prio="0.0"
seq="1"
rank="0"
minImp="0"
slots="1"
flags="s"
line="26"
module="file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl">
<p.nodeTest role="match" test="element(Q{}t)"/>
<param role="action"
baseUri="file:/Users/mike/w3c/xslt30-test-B/tests/insn/for-each-group/for-each-group-085.xsl"
ns="xsl=~ xs=~"
line="27"
name="o"
slot="0"
flags="t"
as="element()*">
<empty role="select"/>
<treat role="conversion" as="element()" diag="8|0|XTTE0590|o">
<supplied slot="0"/>
</treat>
</param>
</templateRule>
</ruleChain>
</ruleSet>
</mode>
<namedTemplates/>
<accumulators/>
<functions/>
</stylesheet>
The critical thing here is:
OPT : Lifted (let $g := ...) above (xsl:apply-templates) on line 21
This loop-lifting is clearly incorrect. (Note, the loop-lifting code is completely rewritten in 9.8)
Updated by Michael Kay over 7 years ago
The loop-lifting error is a consequence of an earlier incorrect tree rewrite: the "controlling instruction" held in the current-group() call is not the xsl:for-each-group instruction that is currently its container in the expression tree. This basically means that the cached information has become out-of-date.
This happens when the ForEachGroup instruction is copied, when its containing variable is inlined. The copy operation fails to rebind the link from the current-group call to the ForEachGroup instruction. Added a call on fixupGroupReferences() after the copy() operation to solve the problem.
Updated by Michael Kay over 7 years ago
- Status changed from New to Resolved
- Fix Committed on Branch 9.8 added
Updated by O'Neil Delpratt over 7 years ago
- % Done changed from 0 to 100
- Fixed in Maintenance Release 9.8.0.3 added
Bug fix applied in the Saxon 9.8.0.3 maintenance release.
Updated by O'Neil Delpratt over 7 years ago
- Status changed from Resolved to Closed
Please register to edit this issue