Split comma separated string in xquery?
I have a div element I want to split in xquery
My start<tags>{for $tag in //div[@id='tags']
return
<tag>{$tag}</tag>}</tags>
The target is converting this
<div id="tags">Tagged: tag1, TAG2, tag3</div>
The expected result is
<tags><tag>tag1</tag><t开发者_C百科ag>TAG2</tag><tag>tag3</tag></tags>
Supposedly you can use the tokenize(string, pattern)
function to split strings based on a pattern. SQL Server 2008 doesn't have the function, but this could be your answer If whatever you're using does. I imagine it would look like this if I could get it to work:
<tags>{
for $tag in tokenize(
substring-after(
(//div[@id='tags'])[1],
'Tagged:'
),
','
)
return
<tag>{
normalize-space($tag)
}</tag>
}</tags>
精彩评论