Singleton focus in predicate expressions

Does someone remember the rationale about this? I often see applying templates as an (almost) synonym to for-each'ing over the same set, but with predicate expressions this is no longer true if you use position or context size in the pattern.

 

Intuitively I tried the following:

 

<xsl:template match="x">

   <xsl:apply-templates select="y" />

</xsl:template>

 

<!-- mark first -->

<xsl:template match=".[1]">

   <xsl:copy>

     <xsl:attribute name="class" select=" 'first' " />

   </xsl:copy>

</xsl:template>

 

<!-- shallow copy rest -->

<xsl:template match="."><xsl:copy></xsl:template>

 

<!-- skip last -->

<xsl:template match=".[last()]" />

 

This approach usually works with normal patterns, except of course that you then actually use the position on the child axis. The dot-notation suggests "current item", similar to how it is used in xsl:for-each etc, and I think that is its intent, but it gets singleton focus, so the above code will not return the result one might expect (last() always returns 1, any position in the predicate is always true).

 

I remember vaguely a discussion about this but I can't remember why we decided in this direction, it seems counter-intuitive.

 

(note, this comes from a bug I found, where we faithfully set the context size and position to the size of, and position in the match selection, which can be retrieved through last() and position(), resulting in different behavior in some cases).

 

Cheers,

Abel

Received on Wednesday, 30 September 2015 15:19:27 UTC