you cannot use templating in that way inside XQuery expression. You need to introduce new parameter using xq-param. Something like this:
<xquery>
<xq-param name="item"><var name="item"/></xq-param>
<xq-param name="index"><template><index>${i}</index></template></xq-param>
<xq-expression><![CDATA
let $name := data($item//td[@colspan='1' and @rowspan='1' and @class='desc'//h2//a[1])
let $desc := data($item//td[@colspan='1' and @rowspan='1' and @class='desc']/div[1])
let $price := data($item//div[@class='price']/a[1])
let $counter := data($index//index)
return
<product>
<id>{$counter}</id>
<name>{normalize-space($name)}</name>
<desc>{normalize-space($desc)}</desc>
<price>{normalize-space($price)}</price>
</product>
]]></xq-expression>
</xquery>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
How do I add a loop counter in my output xml? any help. I am trying to add a counter value in the yahoo example...
Thanks for your help
Cheers
Thank you very very much! Super!
you cannot use templating in that way inside XQuery expression. You need to introduce new parameter using xq-param. Something like this:
<xquery>
<xq-param name="item"><var name="item"/></xq-param>
<xq-param name="index"><template><index>${i}</index></template></xq-param>
<xq-expression><![CDATA
let $name := data($item//td[@colspan='1' and @rowspan='1' and @class='desc'//h2//a[1])
let $desc := data($item//td[@colspan='1' and @rowspan='1' and @class='desc']/div[1])
let $price := data($item//div[@class='price']/a[1])
let $counter := data($index//index)
return
<product>
<id>{$counter}</id>
<name>{normalize-space($name)}</name>
<desc>{normalize-space($desc)}</desc>
<price>{normalize-space($price)}</price>
</product>
]]></xq-expression>
</xquery>