简体   繁体   中英

MarkLogic:Searching for a child node in a parent node from local variable

I am storing a document node in a local variable and want to search for a child node from the local variable. Consider the parent to be:

let $parent :=<tempdoc>
                <identifier>
                  <a>1</a>
                  <b>2</b>
                </identifier>
              </tempdoc>

I do not want to insert the parent node as it is a temporary node created in the middle of a code. If I insert the parent as a document I do the following ie searching for a node from an already inserted document.

let $doc := cts:search(//*:identifier,
cts:directory-query(("/tempfiles/parentdocs/"),"1"))

where /tempfiles/parentdocs/ is the directory where the document is saved.

But what if the document is stored on a local variable instead of the database? What should be replaced instead of cts:directory-query so that I can search for the element in the local variable itself.

What are you trying to do with the variable?

Because cts:search is used to return documents from the database.
You already have the "document" now you just want some nodes in the document so you can use xpath to get back the values you want it your local variable.

let $parent :=<tempdoc>
           <identifier>
           <a>1</a>
           <b>2</b>
           </identifier>
           </tempdoc>
return $parent/identifier/element()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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