[xquery-talk] saxon:evaluate with relative xpath

Michael Kay mike at saxonica.com
Sun Dec 26 19:16:03 PST 2010


saxon:evaluate evaluates the given XPath expression using the context 
node from the call to saxon:evaluate. So yes, the path can be relative. 
Just change "/author[1]" to "author[1]".

Michael Kay
Saxonica

On 24/12/2010 05:33, Hisham Benotman wrote:
> Hi
>
> Can I run dynamic RELATIVE xpath using saxon:evaluate? I retrieve book 
> elements from books.xml file and I want to navigate these elements 
> using relative xpaths and saxon:evaluate. It seems saxon:evaluate 
> understands only absolute paths that starts from the root element.
>
> I am using saxon processor in oXygen.
>
> The following is sample xquery and data files, my application is 
> different.
> XQuery:
> <Authors>
> {
>    (: Step One I get the dynamic path from paths.xml file  :)
>    let $author_path := data(doc('paths.xml')/Xpaths/Author_Path)
>    for $elem2 in doc('Books.xml')/Books/Book  (:Get book elements:)
>        return $elem2/saxon:evaluate($author_path)  (: Want to navigate 
> a book element here but it does not work:)
>  }
> </Authors>
> ------------------------------------------------------------
> Data file books.xml
> <Books>
> <Book>
> <author>John</author>
> <Title>XQuery</Title>
> </Book>
> <Book>
> <author>Tim</author>
> <Title>XSLT</Title>
> </Book>
> </Books>
> ---------------------------------------------------------------------------------------------
> File that contains xpaths that will be loaded and run dynamically
> paths.xml
> <Xpaths>
> <Author_Path>  /author[1] </Author_Path>
> </Xpaths>
> --------------------------------------------------------------------------------------------
>
> The query returns nothing , when I use static path  return 
> $elem2/author[1]
> it works. When I change the path stored in paths.xml to 
> /Books/Book/author[1] it returns all authors in each iteration.
> <Authors>
> <author>John</author>
> <author>Tim</author>
> <author>John</author>
> <author>Tim</author>
> </Authors>
>
> I appreciate any help
>
> Thank you
> Hisham
>
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20101226/c046f109/attachment.htm


More information about the talk mailing list