XQuery: saxon:evaluate with relative xpath
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 2
- Joined: Fri Dec 24, 2010 8:49 am
XQuery: saxon:evaluate with relative xpath
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
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
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XQuery: saxon:evaluate with relative xpath
Hello,
It works fine if you keep the XPaths relative in the paths.xml file:
Don't use "/author[1]", that's an absolute XPath, use "author[1]" instead.
Regards,
Adrian
It works fine if you keep the XPaths relative in the paths.xml file:
Don't use "/author[1]", that's an absolute XPath, use "author[1]" instead.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service