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' :)
return
  doc('/path/to/file.xml')/path/to/$media/title

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:
  <people>
    <person name="bob" />
    <person name="jim" />
    <person name="bob" />
    <person name="ryan" />
  </people>

So I'd display something like:

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

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')
return
  xdmp:node-delete(doc($file)/$person)

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)
        return
                xdmp:eval(concat("xdmp:node-delete(", $node, ")"))
}

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

Cheers,

Eric
_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

Reply via email to