Can I use something like following in xquery? Basically I want to use string variable as a tag. I am using web harvest to extract data. Any help or pointers appreciated.
declare variable $doc as node() external;
declare variable $tag as xs:string;
let $tag := $doc//div[@class=details]//tr[1]/td[1]
return
<$tag>{$doc//div[@class=details]//tr[1]/td[2]</$tag>
Use the element constructor element { $tag } { $content }
.
There are two additional problems with your query:
$tag
as a variable, you're hiding it anywayThis code should work in quite everything but MSSQL which does not support variable names in element constructor's tag name fields:
declare variable $doc as node() external;
let $tag := $doc//div[@class=details]//tr[1]/td[1]
return
element { $tag } { $doc//div[@class=details]//tr[1]/td[2] }