开发者

Xquery problem in counting

Xquery problem in counting

Using XQuery:

List the id, name, publisher and platforms for each game that is supported by more than one platform. Platforms should be enclosed in one XML tag d开发者_Python百科elimited by a comma.

I am getting problem in thinking that how do i count the patforms. The platforms that I need to count is given like in the above figure. Playstation3,XBox are the patlforms for one game. Outside the box, under it, that format of data is given.Please help me in it.


This XQuery:

element result {
   for $game in /games/game[tokenize(Platform,',')[2]]
   return element game {
             $game/(ID|Name|Publisher|Platform)
          }
}

With this input:

<games>
    <game>
        <ID>B003JVKHEQ</ID>
        <Name>Duty</Name>
        <Publisher>AC</Publisher>
        <ESRB>M</ESRB>
        <Motion>False</Motion>
        <Platform>Playstation3,XBox</Platform>
    </game>
</games>

Output:

<result>
    <game>
        <ID>B003JVKHEQ</ID>
        <Name>Duty</Name>
        <Publisher>AC</Publisher>
        <Platform>Playstation3,XBox</Platform>
    </game>
</result>

Edit: With literal result elements

 <result>{
   for $game in /games/game[tokenize(Platform,',')[2]]
   return  <game>{
              $game/(ID|Name|Publisher|Platform)
          }</game>
}</result>


If your XQuery engine supports XPath 2.0 you can use the tokenize function to count items of a comma separated list:

count(tokenize("Playstation3,XBox",","))

Does that help? If not could you please provide a complete example with XML input and expected result. Thank you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜