Reputation: 1147
How can I assign a variable to cts:document-query(). I have sample code to read from file system then assign variable to document-query(). But it spool out errors.
case 1) working without assign variable to document-query.
let $list-pdf := cts:search(/,cts:and-query((
cts:directory-query("/pdf/"),
cts:document-query(("/pdf/US1610547.pdf", "/pdf/US1696102.pdf",
"/pdf/US1953345.pdf")))
for $pdf in $list-pdf
return base-uri($pdf)
return result:
/pdf/US1610547.pdf
/pdf/US1696102.pdf
Case 2 - I assign variable to document-query() after reading from file system. MarkLogic gives me errors.
let $pdf := xdmp:filesystem-file("/output/listpdf.txt")
let $pdfs := tokenize($pdf,"\n")
let $list-pdf := cts:search(/,cts:and-query((
cts:directory-query("/pdf/"),
cts:document-query(($pdfs))
)))
for $pdf in $list-pdf
return base-uri($pdf)
return errorcode:
[1.0-ml] XDMP-URI: cts:document-query(("/pdf/US1610547.pdf", "/pdf/US1696102.pdf",...)) -- Invalid URI format: ""
Upvotes: 1
Views: 50
Reputation: 11771
The error message indicates that the result of tokenization includes an empty string item among the sequence of URIs:
-- Invalid URI format: ""
You can apply a predicate after tokenizing to exclude empty strings (or use more elaborate logic, depending on how much your input can be trusted), i.e.:
let $pdfs := tokenize($pdf,"\n")[. ne ""]
Upvotes: 3