- From: Kay, Michael <Michael.Kay@softwareag.com>
- Date: Tue, 7 Jan 2003 15:59:45 +0100
- To: Howard Katz <howardk@fatdog.com>, www-ql@w3.org
> > (salary, bonus) > > with the following commentary: "This expression contains all > salary children of the context node followed by all bonus children" > > Can this expression be used outside a location path? I can > see returning this expression as a function result, but can > someone provide other examples of valid use? And in such a > case, what is the meaning of "context node"? > Sure, the expression can be used anywhere, for example fn:average((salary, bonus)) returns the average of this sequence - in this case it's actually the same as fn:average(salary | bonus) Or you could write: (salary, bonus)[. > 0] to exclude the values that are negative. In fact, writing the expression within a location path is one of the least useful places to use it, since the results of a path expression are always in document order. So person/(salary,bonus) actually returns the same result as person/(salary|bonus). The "context node" is exactly what it would be if you wrote the expression "salary" instead of "(salary, bonus)". Another common use case is when building a sequence recursively: <xsl:function name="reverse"> <xsl:param name="p"/> <xsl:result select="if ($p) then (reverse($p[position()!=1]), $p[1]) else ()"/> </xsl:function> Michael Kay
Received on Tuesday, 7 January 2003 10:00:01 UTC