I am trying to use xpath on already xpath element using javascript query. Below code giving error
[javascript]
JS-JAVASCRIPT: b.xpath("/cart") -- Error running JavaScript request: TypeError: undefined is not a function.
var a = cts.doc("/users/mydoc.xml");
var b = a.xpath("/user/carts");
b.xpath("/cart");
The xpath
function in Server-side JavaScript returns a Sequence. Either iterate over that, or if you expect only one result, apply fn.head
on it. Also make sure to use relative XPaths if continuing from a descendant. Prefix your path with .
, or just use relative paths:
var a = cts.doc("/users/mydoc.xml");
var b = fn.head(a.xpath("/user/carts"));
b.xpath("cart");
HTH!