W3C home > Mailing lists > Public > www-ql@w3.org > January to March 2003

RE: meaning of (salary, bonus)

From: Kay, Michael <Michael.Kay@softwareag.com>
Date: Tue, 7 Jan 2003 15:59:45 +0100
Message-ID: <DFF2AC9E3583D511A21F0008C7E621060453DF1C@daemsg02.software-ag.de>
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

  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 ()"/>

Michael Kay
Received on Tuesday, 7 January 2003 10:00:01 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:15 UTC