cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

context_string alternatives

ChrisWestern
12-Amethyst

context_string alternatives

Hello all,


I would like to get a full valid context location path (with NS local-name etc) from the current node/oid/cursor pos in Editor 6.1 and the only obvious option i have seen so far is 'context_string'.


As this outputs a kind of psuedo location path not valid in its raw form to re-use, i was wondereding if there might be other quick options i have overlooked that anyone can suggest without going around the block and back!?


<doc><a:chap><b:sec><b:other>text</b:other><c:para>text1</c:para><c:para>text2|


context_string gives: "doc(a:chap(b:sec(b:other()c:para()c:para("


(i can post process with some regEx this but be nice not to!)


need to have something valid like "//doc/node()[local-name()='chap']/node()[local-name()='sec']/node()[local-name()='para'][2]"


(similar to get-context xpath function in APP)


Many thanks!


Chris






2 REPLIES 2

Hi Chris—

You might be able to work out a way to do this using either Javascript or Java (called via Javascript if you like). But it would probably be just as easy to write your own function to do this. It would probably look something like this:

function oid2xpath(oid) {
if (!oid_valid(oid)) { return; }
local xpath = ";
local this_step = ";
if (index(oid_name(oid),':')>0) {
this_step .= "*[local-name()=";
this_step .= substr(oid_name(oid), index(oid_name(oid),':') + 1);
this_step .= "]";
}
else {
this_step .= oid_name(oid);
}
local pos = oid_xpath_string(oid, "count(preceding-sibling::" . this_step . ") + 1");
this_step .= "[" . pos . "]";
return oid2xpath(oid_parent(oid)) . "/" . this_step;
}

--Clay

That’s great thank you for the insight Clay!



Looks like a custom output function or post process it is.



Cheers

Chris


Announcements

Top Tags