[xquery-talk] Getting node position in a for statement

David Carlisle davidc at nag.co.uk
Mon Jun 16 16:13:52 PDT 2008



> I want to return the position of <tr> within its parent.

well either count that dirctly, using count(1+preceding-sibling::tr) or,
if you wnat to use position() (or at) you need to split it up into two
iterations, one over tables, and one over the rows.


for $table  in //table
return
for $rows at $p in $table/tbody/tr
	let $cells := count($rows/th)
return
<row position="{$p} cellcount="{$cells}" >{data($table/title)}</row>




or


//table/(tbody/tr)/<row position="{position()} cellcount="{count(th)}">
      {ancestor::table/title/data(.)}</row>


David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________


More information about the talk mailing list