Hi Anil, It depends on the context whether the fn prefix is required. In a main module if nothing else is declared as the default, it is not required (because it is the default function namespace). In a library module in MarkLogic Server, the default namespace is the namespace of the library, so it is required without a default namespace declaration.
It is really a matter of style though. Personally, I like to just get in the habit of always prefixing my fn functions so that the code will work in any environment. Other people might have different styles they prefer. You might also want to look at the Shakespeare demo app on the developer site (http://developer.marklogic.com/code/#bill). It is a bit out of date, but it does a lot of what you are trying to do and might give you some ideas how to do the things you are doing. -Danny From: [email protected] [mailto:[email protected]] On Behalf Of Anil Shekhar Sent: Wednesday, September 23, 2009 1:47 PM To: [email protected] Subject: RE: [MarkLogic Dev General] FLWOR clarification ... Danny: ------- Thanks Danny. Yes. I want to query the entire database to get all the documents and search for speakers along with their lines in each document. I am trying this scenario to learn the language and its nuts and bolts. Is "fn:" required? Is this the default namespace? Florent: -------- I tried your approach of declaring the variable type. It did not help. Can there be more than 1 return from 1 FLWOR expression? I was thinking of this ... for $d in doc() (: Print the document name here ... return (<h1>{document-uri($d)}</h1>) :) let $speech := $d//SPEECH let $speaker := $speech/SPEAKER let $lines := $speech/LINE (: Look through each speaker in the document and display all the line elements of that speaker :) return ( <h3>{$speaker/text()}</h3>, <p>{for $line in $lines return $line/text()}</p> ) Is this possible? Any other suggestions? Thanks so much Anil Shekhar > From: [email protected] > To: [email protected]; [email protected] > Date: Wed, 23 Sep 2009 11:55:35 -0700 > Subject: RE: [MarkLogic Dev General] FLWOR clarification ... > CC: > > Hi Anil, > > Another quick observation here: Your queries all return the entire database > and process the whole database in a single query. You might want to do this > one play at a time (or even one act or scene at a time). As it is, you end up > sending a huge result back to the browser. So perhaps instead of: > > for $speech in doc()//SPEECH > > you can do something like: > > for $speech in fn:doc("/shakespeare/plays/as_you.xml")//SPEECH > return .... > > -Danny > > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Florent Georges > Sent: Wednesday, September 23, 2009 11:40 AM > To: General Mark Logic Developer Discussion > Subject: Re: [MarkLogic Dev General] FLWOR clarification ... > > Anil Shekhar wrote: > > Hi, > > > for $speech in doc()//SPEECH > > let $speaker := $speech/SPEAKER > > Here, you loop over each speech. For each one of them, you bind > the variable $speech to it, and then evaluate the loop body. > Within which you bind the variable $speaker, etc. > > > for $d in doc() > > let $speech := $d//SPEECH > > let $speaker := $speech/SPEAKER > > Here, you loop over document nodes. For each of them, you bind > all its speeches at once to the variable $speech. So $speaker in > turn is bound to the speakers of every speeches in this document. > And by <h3>{ $speaker/text() }</h3> you create an element the > content of which is the concatenation of all the text node children > of all the speaker elements. > > This is a good example where declaring the type (an arity) of > the variables would have helped you: > > for $d in doc() > let $speech as element(SPEECH) := $d//SPEECH > let $speaker as element(SPEAKER) := $speech/SPEAKER > > Hope that helps (by the way, upper case element names look kind > of weird,) regards, > > -- > Florent Georges > http://www.fgeorges.org/ > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > General mailing list > [email protected] > http://xqzone.com/mailman/listinfo/general ________________________________ Insert movie times and more without leaving Hotmail(r). See how.<http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009>
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
