[英]not able to write for loop in XQuery MarkLogic
I am trying to write a for loop as:我正在尝试将 for 循环编写为:
for $conditions in $contents
return fn:concat("The value of contents is : ", $conditions)
However in place of pages its returning the values inside the $contents
variable.但是,它代替页面返回$contents
变量中的值。
I am working on a mapping file in marklogic and trying to get the values of the elements from that mapping file.我正在处理 marklogic 中的映射文件,并尝试从该映射文件中获取元素的值。
"contents": {
"sample": {
"feature": ".........",
"contents": "value1",
"contents": {..................}
now I want to loop for the "contents" element from the mapping file but my for loop is returning me the whole "contents" map instead of giving output as: "The value of contents is: value1" Can anyone help in this regard?现在我想从映射文件中循环“内容”元素,但我的 for 循环返回给我整个“内容”map,而不是给 output 作为:“内容的值是:value1”有人可以在这方面提供帮助吗?
Your question is not very clear, as mentioned by others as well, but let me hazard a guess.正如其他人所提到的,您的问题不是很清楚,但让我冒险猜测一下。 You sometimes want to count items.您有时想计算项目。 You can do that with something as simple as fn:count($books)
.你可以用fn:count($books)
这样简单的方法来做到这一点。
In other cases you might want to keep track at which item number you are currently.在其他情况下,您可能希望跟踪您当前所在的项目编号。 In other programming languages you might write a for-loop which increments a variable with i = i + 1
.在其他编程语言中,您可能会编写一个 for 循环,该循环使用i = i + 1
递增一个变量。 You can't do that in XQuery, since it is a functional language, and those typically do not allow this.您不能在 XQuery 中这样做,因为它是一种函数式语言,而那些通常不允许这样做。
There are ways around in MarkLogic, but there is a simple trick. MarkLogic 有很多方法,但有一个简单的技巧。 The FLWOR statement can keep track of the current position for you using the at
keyword. FLWOR 语句可以使用at
关键字为您跟踪当前的 position。
You use it like this:你像这样使用它:
for $item at $page in $books
return fn:concat("This is the page number... ", $page)
HTH! !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.