[xsl] Obtain depth to create relative path

Subject: [xsl] Obtain depth to create relative path
From: "ASB 98" <asb98.doc@xxxxxxxxxxxxxx>
Date: Wed, 23 Aug 2006 10:02:12 +0100
Dear All,

Using eXist database as data repository, including built in xpath and
xquery functions.

My current xquery search needs to determine the depth of the returned
node ($x) in the document - from the root.
I would then like to use this to generate the relative path that is
needed to access a node higher up the structure ($x will always be
deeper in the document).

So for example if the depth was 10, and the specific item I wished to
retrieve was at level 5, then I would want to create the relative
path: $x/../../../../../ps:specific-nodename
 i.e. ( (10-5) x "/.." ) + /ps:specific-nodename       (probably
done within a loop)

Below is what I have so far, but don't know how to get position or
counter to function on $x.

Can this be done without xsl? how can the relative path value be created?
TIA

- - - - - -
declare namespace ps="http://www.pasoa.org/schemas/version025/PStruct.xsd";;
declare namespace wsa=" http://schemas.xmlsoap.org/ws/2004/03/addressing";;
declare namespace ex="http://www.example.com";;
declare namespace ph=" http://www.pasoa.org/schemas/version025/PHeader.xsd";;
declare namespace pq="
http://www.pasoa.org/schemas/version025/pquery/ProvenanceQuery.xsd ";
declare namespace xsl=" http://www.w3.org/Style/XSL/ ";
declare namespace fc="http://www.w3.org/2005/02/xpath-functions ";

for $x at $i in
/ps:pstruct/ps:interactionRecord/ps:interactionKey/ps:messageSink[wsa:Address=&quot;http://www.example.com/actors/store&quot;]/../../ps:sender/ps:interactionPAssertion/ps:content/ex:envelope/ex:store
[ex:location=&quot;/home/sj/data/file1&quot;]/../../ex:envelope/ex:store/ex:data

let $pos := fn:position()                      <!-- this is not working ->
let $count := count(ancestor::*)+1      <!-- this is not working ->

let $view := $x/../../../../..                   <!-- this is what the
depth is to be used to set ->
return
<resultPQ counter="{$i}">
 <testcount>{$pos} and {$count}</testcount>
 <qdhdata>{$x}</qdhdata>
 <qdhkey>{$view/../ps:interactionKey}</qdhkey>
 <qdhviewtype>{$view/name()}</qdhviewtype>
 <qdhsender>{$view/../ps:sender}</qdhsender>
 <qdhreceiver>{$view/../ps:receiver}</qdhreceiver>
</resultPQ>



- - - -

Many thanks! asb

Current Thread