[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
for $rows at $p in $table/tbody/tr
	let $cells := count($rows/th)
<row position="{$p} cellcount="{$cells}" >{data($table/title)}</row>


//table/(tbody/tr)/<row position="{position()} cellcount="{count(th)}">


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