Xquery计数问题

发布于 2024-10-03 06:18:33 字数 233 浏览 0 评论 0原文

alt text

使用 XQuery:

列出多个支持的每个游戏的 id、名称、发行商和平台 平台。平台应包含在一个以逗号分隔的 XML 标记中。

我在思考如何计算平台时遇到问题。我需要统计的平台如上图所示。 Playstation3、XBox是一款游戏的平台。在框外,在其下方,给出了数据格式。请帮助我。

alt text

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 delimited 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放低过去 2024-10-10 06:18:33

此 XQuery:

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

使用此输入:

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

输出:

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

编辑:使用文字结果元素

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

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>
守不住的情 2024-10-10 06:18:33

如果您的 XQuery 引擎支持 XPath 2.0,您可以使用 tokenize 函数来计算逗号分隔列表的项目数:

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

这有帮助吗?如果没有,请提供一个包含 XML 输入和预期结果的完整示例。谢谢。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文