【问题标题】:XQuery- concat or string-join?XQuery- concat 或 string-join?
【发布时间】:2014-09-13 06:22:33
【问题描述】:

下面是 XML 结构。

<Docs>
 <Doc>
  <Title>Physics</Title>
  <Desc>
    <Part n="Part 1">
      <Chap c="1"/>
      <Chap c="2"/>
      <Chap c="4"/>
    </Part>
  </Desc>
 </Doc>
 <Doc>
  <Title>Physics</Title>
  <Desc>
    <Part n="Part 2">
      <Chap c="2"/>
      <Chap c="3"/>
      <Chap c="4"/>
    </Part>
  </Desc>
 </Doc>
</Docs>

我的输出如下-

<Title>Physics,#,Part 1 - 1,2,4</Title>
<Title>Physics,#,Part 2 - 2,3,4</Title>

我尝试使用concatstring-join 进行各种组合,但都是徒劳的:(

【问题讨论】:

  • 您的 XML 文档不正确。请你先修好吗?
  • “我尝试了各种组合” - 请显示您尝试过的什么,以便我们帮助您解决具体问题。

标签: xml xquery basex


【解决方案1】:

晚上,我又玩了一遍,得到了答案,虽然不是我需要的确切答案,但足以满足我的需要-

let $a :=
<Docs>
 <Doc>
  <Title>Physics</Title>
  <Desc>
    <Part n="Part 1">
      <Chap c="1"/>
      <Chap c="2"/>
      <Chap c="4"/>
    </Part>
  </Desc>
 </Doc>
 <Doc>
  <Title>Physics</Title>
  <Desc>
    <Part n="Part 2">
      <Chap c="2"/>
      <Chap c="3"/>
      <Chap c="4"/>
    </Part>
  </Desc>
 </Doc>
</Docs>


for $x in $a//Doc
return 
<Title>{
concat($x/Title,"#", 
    string-join(
        ($x/Desc/Part/@n, " - ", string-join(($x/Desc/Part/Chap/@c, ""),",")),""))
}</Title>

【讨论】:

    猜你喜欢
    • 2019-07-09
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2016-02-26
    相关资源
    最近更新 更多