function Reverse() in XPath 2.0 : how can use it to evaluate an expression?

jaydee

New Member
Please go easy on me , this is my first time using \[code\]XPath 2.0\[/code\] :)Given the following code : \[code\]import net.sf.saxon.expr.Expression;import net.sf.saxon.expr.StaticContext;import net.sf.saxon.functions.CompileTimeFunction;import net.sf.saxon.sort.Reverser;import net.sf.saxon.trans.XPathException;public class MyReverse extends CompileTimeFunction { public Expression simplify(StaticContext env) throws XPathException { Reverser a = new Reverser(argument[0]); return a.simplify(env); }}\[/code\]I want to reverse the query : \[code\]String query = "inventory/book/chapter[3]/preceding-sibling::chapter//title";Object myQuery= xpath.evaluate(query,doc,XPathConstants.NODESET);\[/code\]for my XML file (I can attach the XML file if you wish ,so please say so if it's indeed required!)Now from my understanding if I do this : \[code\]MyReverse rev = new MyReverse();\[/code\]then if I try to use the method \[code\]evaluateAsString\[/code\] like this : \[code\]rev.evaluateAsString(arg0)\[/code\]then \[code\]arg0\[/code\] should be a \[code\]XPathContext\[/code\] object . How can I use my query with the above method ? Regards EDIT 1:In the example that dear Mr. @Dimitre Novatchev wrote , what is needed is all the nodes from node \[code\]X\[/code\] , to the upper side of the document.However , if one of \[code\]X's\[/code\] siblings , has children , then I need to present the sibling and only then his (the sibling's) children (and after that move on to the next sibling , and the same all over again) , and not the child of the sibling & only then - the sibling . I'm sorry for not mentioning & explaining this earlier thanks again :)
 
Back
Top