|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Getting node position in a for statementVallone, Philip Mr CTR USA AMC Philip.Vallone at us.army.milMon Jun 16 09:05:27 PDT 2008
Hi List, I am trying to use xquery to print out details about <tables> in my xml. Take the following XML. <root> <table> <title>Table 1 - Index</title> <tbody> <tr> <th>Index Number</th> </tr> <tr> <th>1</th> </tr> </tbody> </table> <table> <title>Table 2 - Dictionary</title> <tbody> <tr> <th>Word</th> <th>Definition</th> </tr> <tr> <th>Some word</th> <th>some definition</th> </tr> <tr> <th>Some word</th> <th>some definition</th> </tr> <tr> <th>Some word</th> <th>some definition</th> </tr> </tbody> </table> </root> My desired output would be to count the <tr> position within each table/tbody: <row position="1" cellcount="1">Table 1 - Index</row> <row position="2" cellcount="1">Table 1 - Index</row> <row position="1" cellcount="2">Table 2 - Dictionary</row> <row position="2" cellcount="2">Table 2 - Dictionary</row> <row position="3" cellcount="2">Table 2 - Dictionary</row> <row position="4" cellcount="2">Table 2 - Dictionary</row> Here is my xq expression so far: for $rows in //table/tbody/tr let $cells := count($rows/th) let $title := $rows/ancestor::table/title let $pos := $rows/position() return <row position="{$pos}" cellcount="{$cells}" >{data($title)}</row> It currently returns "1" for every position. Thanks for the help. Phil
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






