Helen, I'm not sure this will make a difference, but try these alternatives:
fn:base-uri(doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)]) fn:document-uri(doc()[ns1:article//ns1:sub[not(@temp1 or @temp2)]]) I'm not sure (internally) how this usage differs from the other, so it may or may not work. In the document-uri case, I made a change to the XPath to avoid having to use root function, but you can try either way. Doug Glidden Software Engineer The Boeing Company douglass.a.glid...@boeing.com -----Original Message----- From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Helen Chen Sent: Wednesday, January 20, 2010 16:56 To: General Mark Logic Developer Discussion Cc: Helen Chen Subject: Re: [MarkLogic Dev General] question about cts:search Hi Geert, Thanks. Now I understand why sometimes when I use document-uri() and it returns empty sequence, that's because it is not document element. So I did the following test: ------------- for $doc in doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)] let $uri := try { base-uri($doc) } catch ($e) { () } where not($uri) return $doc it returns empty sequence ----------------------- for $i in doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)] return base-uri($i) it returns 7 uris and they are actually the same uri (/pt/ajr_1.xml), just because there are 7 ns1:sub nodes found. ------------------ when I tried to run doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)]/fn:base-uri(.) I got error : Description: XDMP-NOTANODE: doc()/child::ns1:article/ descendant::ns1:sub[attribute::temp1 or attribute::temp2]/base-uri(.) -- xs:anyURI("/pt/ajr_1.xml") is not a node the base-rui() function returns type anyURI, not a node, is this what it complains? Thanks, Helen On Jan 20, 2010, at 4:19 PM, Geert Josten wrote: > Hi Helen, > > I personally prefer base-uri, as it navigates up to the root itself if > necessary. You can read more about the two functions here: > > http://developer.marklogic.com/pubs/4.1/apidocs/AccessorBuiltins.html# > fn :document-uri (particularly read Summary and User Notes) > > Kind regards, > Geert > >> -----Original Message----- >> From: general-boun...@developer.marklogic.com >> [mailto:general-boun...@developer.marklogic.com] On Behalf Of Helen >> Chen >> Sent: woensdag 20 januari 2010 22:05 >> To: General Mark Logic Developer Discussion >> Cc: Helen Chen >> Subject: Re: [MarkLogic Dev General] question about cts:search >> >> Hi Geert, >> >> I run your query >> for $doc in doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)] let >> $uri := try { base-uri($doc) } catch ($e) { () } where >> not($uri) return >> $doc >> >> and it returns empty sequence. >> ------------ >> >> if I take "not" out in the where clause, like for $doc in >> doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)] let $uri := try { >> base-uri($doc) } catch ($e) { () } where ($uri) return >> $doc >> >> I got 7 nodes out, these nodes only have attributes, no sub nodes >> inside, like <ns1:sub file="1"/>, and they are all in the same xml >> file, the xml is: /pt/ajr_1.xml >> >> -------------- >> I actually can run >> >> doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)]/fn:root(.) >> >> and it returns the root of file /pt/ajr_1.xml, and only one result >> node >> >> --------- >> but I cannot run >> doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)]/fn:document- >> uri(fn:root(.)) >> >> >> I thought it was because of multiple node returned, but when I use >> fn:root(.) at the end, it returns only one node, so it must be >> something else. >> >> when I do : doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)]/ >> fn:document-uri(.) >> it returns empty sequence >> >> when I do: doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)]/ >> fn:document-uri(fn:root(.)) >> it gives error >> >> when I do: doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)]/ >> fn:document-uri(fn:root(.)/ns1:article) >> this query makes sure only one node for >> fn:document-uri() function, but it returns empty sequence >> >> It seems that fn:root() pass root element to the >> fn:document-uri() and >> it does not like it, if I pass node to it, it returns empty sequence. >> Can we use fn:document-uri() or fn:base-uri() at the end of query? >> >> >> Thanks, Helen >> >> >> On Jan 20, 2010, at 3:33 PM, Geert Josten wrote: >> >>> Hi Helen, >>> >>>> I changed and I got the same error as when I use fn:base-uri(.) >>>> >>>> Description: XDMP-NOTANODE: doc()/child::ns1:article/ >>>> descendant::ns1:sub[not(attribute::temp1 or >>>> attribute::temp2)]/document-uri(root(.)) -- >>>> xs:anyURI("/pt/ajr_1.xml") is not a node >>>> >>>> The result is really only one document, but it seems that >> I cannot >>>> put >>>> fn:document-uri at the end of the query. >>> >>> This is actually quite strange. Doc() always returns nodes >> or empty >>> sequence, child always returns nodes or empty sequence, descendant >>> always returns nodes or empty sequence, so this is very >> odd. Even a >>> text or binary document would result in a node. >>> >>> Could you try the following to figure out which document is >> causing >>> the trouble? >>> >>> for $doc in doc()/ns1:article//ns1:sub[not(@temp1 or @temp2)] >>> let $uri := try { base-uri($doc) } catch ($e) { () } >>> where not($uri) >>> return >>> $doc >>> >>> Kind regards, >>> Geert >>> >>> >>> Drs. G.P.H. Josten >>> Consultant >>> >>> >>> http://www.daidalos.nl/ >>> Daidalos BV >>> Source of Innovation >>> Hoekeindsehof 1-4 >>> 2665 JZ Bleiswijk >>> Tel.: +31 (0) 10 850 1200 >>> Fax: +31 (0) 10 850 1199 >>> http://www.daidalos.nl/ >>> KvK 27164984 >>> De informatie - verzonden in of met dit emailbericht - is >> afkomstig >>> van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. >>> Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het >>> te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend. >>> >>> >>> >>> _______________________________________________ >>> General mailing list >>> General@developer.marklogic.com >>> http://xqzone.com/mailman/listinfo/general >> >> _______________________________________________ >> General mailing list >> General@developer.marklogic.com >> http://xqzone.com/mailman/listinfo/general >> _______________________________________________ > General mailing list > General@developer.marklogic.com > http://xqzone.com/mailman/listinfo/general _______________________________________________ General mailing list General@developer.marklogic.com http://xqzone.com/mailman/listinfo/general _______________________________________________ General mailing list General@developer.marklogic.com http://xqzone.com/mailman/listinfo/general