[MarkLogic Dev General] xpath string construction

Eric Palmitesta eric.palmitesta at utoronto.ca
Fri Oct 10 11:43:29 PDT 2008

Is there a specific reason why one can't construct an xpath out of a string?

For example,

let $media := 'book' (: or 'journal', or 'article' :)

Another use case, I want to display a list of items, and offer a 
'delete' link for each item.

lets say /people.xml contained the following:
     <person name="bob" />
     <person name="jim" />
     <person name="bob" />
     <person name="ryan" />

So I'd display something like:

for $person in doc('/people.xml')/people/person
     <a href="delete.xqy?path={ xdmp:path($person) }>delete</a>

This will give me nice delete links like 
"delete.xqy?path=/people/person[1]", but in the supposed delete.xqy, I'd 
want to do something similar to:

let $file := '/people.xml'
let $person := xdmp:get-request-field('path')

I can't, of course, the doc call will be fine but I can't construct 
xpath with a string.  And the node-delete (and any other 
node-manipulation function) requires actual nodes, not strings.

I end up having to write eval-based utility functions:

define function util:remove-element($uri as xs:string, $xpath as xs:string)
	let $node := concat("doc('", $uri, "')", $xpath)
		xdmp:eval(concat("xdmp:node-delete(", $node, ")"))

Please tell me I'm all wrong and there's a better way.



More information about the General mailing list