簡體   English   中英

無法在 XQuery MarkLogic 中編寫 for 循環

[英]not able to write for loop in XQuery MarkLogic

我正在嘗試將 for 循環編寫為:

for $conditions in $contents
return fn:concat("The value of contents is : ", $conditions)

但是,它代替頁面返回$contents變量中的值。

我正在處理 marklogic 中的映射文件,並嘗試從該映射文件中獲取元素的值。

"contents": {
      "sample": {
        "feature": ".........",
        "contents": "value1",
        "contents": {..................}

現在我想從映射文件中循環“內容”元素,但我的 for 循環返回給我整個“內容”map,而不是給 output 作為:“內容的值是:value1”有人可以在這方面提供幫助嗎?

正如其他人所提到的,您的問題不是很清楚,但讓我冒險猜測一下。 您有時想計算項目。 你可以用fn:count($books)這樣簡單的方法來做到這一點。

在其他情況下,您可能希望跟蹤您當前所在的項目編號。 在其他編程語言中,您可能會編寫一個 for 循環,該循環使用i = i + 1遞增一個變量。 您不能在 XQuery 中這樣做,因為它是一種函數式語言,而那些通常不允許這樣做。

MarkLogic 有很多方法,但有一個簡單的技巧。 FLWOR 語句可以使用at關鍵字為您跟蹤當前的 position。

你像這樣使用它:

for $item at $page in $books
return fn:concat("This is the page number... ", $page)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM