简体   繁体   English

使用Marklogic Xquery数据填充

[英]Using Marklogic Xquery data population

I have the data as below manner. 我有以下方式的数据。

<Status>Active Leave Terminated</Status>
<date>05/06/2014 09/10/2014 01/10/2015</date>

I want to get the data as in the below manner. 我想按以下方式获取数据。

<status>Active</Status>
<date>05/06/2014</date>

<status>Leave</Status>
<date>09/10/2014</date>

<status>Terminated</Status>
<date>01/10/2015</date>

please help me on the query, to retrieve the data as specified above. 请帮助我进行查询,以检索上面指定的数据。

Well, you have a string and want to split it at the whitestapces. 好吧,您有一个字符串,想在白钉处将其拆分。 That's what tokenize() is for and \\s is a whitespace. 这就是tokenize()目的, \\s是一个空格。 To get the corresponding date you can get the current position in the for loop using at . 要获得相应的日期,你可以使用获得的当前位置在for循环at Together it looks something like this (note that I assume that the input data is the current context item): 在一起看起来像这样(请注意,我假设输入数据是当前上下文项):

let $dates := tokenize(date, "\s+")
for $status at $pos in tokenize(Status, "\s+")
return (
  <status>{$status}</status>,
  <date>{$dates[$pos]}</date>
)

You did not indicate whether your data is on the file system or already loaded into MarkLogic. 您没有指出数据是在文件系统上还是已经加载到MarkLogic中。 It's also not clear if this is something you need to do once on a small set of data or on an on-going basis with a lot of data. 还不清楚这是否是您需要根据少量数据集还是对大量数据进行一次处理。

If it's on the file system, you can transform it as it is being loaded. 如果它在文件系统上,则可以在加载时对其进行转换。 For instance, MarkLogic Content Pump can apply a transformation during load . 例如, MarkLogic Content Pump可以在load期间应用转换

If you have already loaded the content and you want to transform it in place, you can use Corb2 . 如果您已经加载了内容并且想要对其进行转换,则可以使用Corb2

If you have a small amount of data, then you can just loop across it using Query Console. 如果数据量很少,则可以使用查询控制台遍历数据。

Regardless of how you apply the transformation code, dirkk's answer shows how you need to change it. 不管您如何应用转换代码,dirkk的答案都显示了如何更改它。 If you are updating content already in your database, you'll xdmp:node-delete() the original Status and date elements and xdmp:node-insert-child() the new ones. 如果要更新数据库中已有的内容,则将xdmp:node-delete()保留为原始Status和date元素,并将xdmp:node-insert-child()保留为新元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM