I am using a tool web harvest to scrape data from a website. I used xquery to output data as an xml file. I need to use a variable tag, for which I tried using the following:
我正在使用工具网络收获来从网站上抓取数据。我使用xquery将数据输出为xml文件。我需要使用变量标记,我尝试使用以下代码:
for $i in (4 to ($count - 2))
return <concat("detail", $i)>{$doc//td[@class='body_copy']/b/../text()[$i]}</concat("detail", $i)>
This doesn't work. I also tried putting {} as in <{concat("detail", $i)}>
Any idea how to accomplish this? Or is it not achievable or not advisable?
这不起作用。我也尝试将{}放在<{concat(“detail”,$ i)}>任何想法如何实现这一点?或者它是不可实现或不可取的?
1 个解决方案
#1
0
Your syntax to build element dynamically is wrong. Try this way:
您动态构建元素的语法是错误的。试试这种方式:
...
element{concat("detail", $i)}{$doc//td[@class='body_copy']/b/../text()[$i]}
...
Result will be a detailN
element containing the result of the expression in the seccond pair of curly braces.
结果将是一个detailN元素,其中包含第二对花括号中表达式的结果。
#1
0
Your syntax to build element dynamically is wrong. Try this way:
您动态构建元素的语法是错误的。试试这种方式:
...
element{concat("detail", $i)}{$doc//td[@class='body_copy']/b/../text()[$i]}
...
Result will be a detailN
element containing the result of the expression in the seccond pair of curly braces.
结果将是一个detailN元素,其中包含第二对花括号中表达式的结果。