Project

Profile

Help

Question about using position() in select expression of xsl:merge-key

Added by Martin Honnen over 7 years ago

The XSLT 3.0 spec in https://www.w3.org/TR/xslt-30/#merge-keys says about the @select@ expression in @xsl:merge-key@:

The value of Nth merge key value of an item J in a merge input sequence S is the result of the expression in the select attribute of the Nth xsl:merge-key child of the corresponding xsl:merge-source element, or in the absence of the select attribute, the result of the contained sequence constructor. This is evaluated with a singleton focus based on J, or, if streamable=yes is specified on the xsl:merge-source, a singleton focus based on a snapshot of J (see 15.4 Streamable Merging).

Note:

This means that position() and last() return 1 (one).

However, when I try the stylesheet





	
		
			foo 1
			bar 1
			bar 2
			foo 2
			baz 1
		
	
	
	
		
			foo a
			bar a
			bar b
			foo b
			baz a
		
	
	
	
	
	
		
			
				
					
				
				
					
				
				
                    
					
						
					
				
			
		
	
	


with @Saxon-HE 9.8.0.1J@ from the command line with @-it@ I get the following output:


current-merge-key():  1 ; current-merge-group(): foo 1foo a
current-merge-key():  2 ; current-merge-group(): bar 1bar a
current-merge-key():  3 ; current-merge-group(): bar 2bar b
current-merge-key():  4 ; current-merge-group(): foo 2foo b
current-merge-key():  5 ; current-merge-group(): baz 1baz a


   foo a
   bar a
   bar b
   foo b
   baz a

I was looking for some way to do "positional merging" when writing that code but given the clear statement in the spec that @position()@ is always @1@ due to a "singleton focus" it seems the result from Saxon is wrong and it should instead only build one group for the key @1@.

Any thoughts?


Replies (2)

RE: Question about using position() in select expression of xsl:merge-key - Added by Michael Kay over 7 years ago

Yes I think you are right. It was a spec change during the course of spec development that Saxon didn't pick up.

    (1-2/2)

    Please register to reply