kol
kol

Reputation: 106

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 i.e. 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.

Upvotes: 0

Views: 350

Answers (1)

Tyler Replogle
Tyler Replogle

Reputation: 1339

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()

Upvotes: 2

Related Questions