New test, loop-lifting an expression that depends on position()
authorMichael Kay <mike@saxonica.com>
Tue, 24 Apr 2018 17:10:19 +0100
changeset 1836 346f3ba92c11
parent 1835 c3f56f2a3703
child 1837 14d1819c8f0f
New test, loop-lifting an expression that depends on position()
tests/fn/position/_position-test-set.xml
tests/fn/position/position-83.xml
tests/fn/position/position-8301.xsl
--- a/tests/fn/position/_position-test-set.xml	Tue Apr 24 17:09:19 2018 +0100
+++ b/tests/fn/position/_position-test-set.xml	Tue Apr 24 17:10:19 2018 +0100
@@ -3832,4 +3832,21 @@
 </out>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="position-8301">
+      <description>Saxon bug 3758: loop-lifting subexpression that depends on position()</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <environment>
+         <source file="position-83.xml" role="."/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="position-8301.xsl"/>
+      </test>
+      <result>
+         <assert>/out = '212'</assert>
+      </result>
+   </test-case>
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/position/position-83.xml	Tue Apr 24 17:10:19 2018 +0100
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+  <element name="S_1">
+      <element name="S_2">
+          <element name="S_3"/>        
+      </element>
+      <element name="S_4"/>    
+  </element>
+</root>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/position/position-8301.xsl	Tue Apr 24 17:10:19 2018 +0100
@@ -0,0 +1,17 @@
+<?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="xs" version="2.0">
+
+    <!-- root -->
+    <xsl:template match="root">
+        <out>
+         <xsl:for-each select="element | element/element[starts-with(@name, 'S')]">
+             <xsl:value-of select="
+                     if (some $x in element/@name
+                         satisfies starts-with($x, 'S') and position() != 1) then
+                         ('1')
+                     else
+                         ('2')"/>
+         </xsl:for-each>
+        </out>
+    </xsl:template>
+</xsl:stylesheet>