XSLT: absolute array-of-positions of a node... ?

I

Ivan_G_S

Hello community!

I'm looking for a possibility to create a kind of URL, which
represents the absolute path to a node.

I have an XML document with multiple-nested paragraphs. (Think of a
file directory tree).

Inside a template that matches paragraphs ( <xsl:template
match="paragraph"> ) I need to be able to say: position of current
paragraph is (for example) /1/3/5/2

Like the command 'pwd' in Linux, but with positions instead of
directory names.
( /#7/#4/#5 instead of /usr/lib/java )

But I am also very thankful for a proposed solution with names,
instead of numbers!!!

Thanx in advice!
 
M

Martin Honnen

Ivan_G_S said:
Inside a template that matches paragraphs ( <xsl:template
match="paragraph"> ) I need to be able to say: position of current
paragraph is (for example) /1/3/5/2

Like the command 'pwd' in Linux, but with positions instead of
directory names.
( /#7/#4/#5 instead of /usr/lib/java )

Do you want the position based on all nodes (use
count(preceding-sibling::node()) or an all elements (use
count(preceding-sibling::*) or on the elements of the same name (use
count(preceding-sibling::paragraph)? For the complete path you need to
walk the ancestor axis.
 
I

Ivan_G_S

Thank you!
But how can I walk the ancestor axis?
I have tried a recursive named template, but I don't know how to call
a template with the parent as new context.

what i need is a naming like:

root (path: 1)
- node (path: 1/1)
- node (path: 1/2)
- - node (path: 1/2/1)
- - node (path: 1/2/2)
- node (path: 1/3)
- - node (path: 1/3/1)
- - node (path: 1/3/2)
- - - node (path: 1/3/1/1)

so, every path name is: "the path of parent" + '/' + "number among
siblings"
 
R

Richard Tobin

Ivan_G_S said:
I'm looking for a possibility to create a kind of URL, which
represents the absolute path to a node.

I have an XML document with multiple-nested paragraphs. (Think of a
file directory tree).

Inside a template that matches paragraphs ( <xsl:template
match="paragraph"> ) I need to be able to say: position of current
paragraph is (for example) /1/3/5/2

There is a standard syntax of just this kind, usable as a fragment
identifier in URIs for XML documents:

http://www.w3.org/TR/xptr-element/

-- Richard
 
J

Joseph Kesselman

See part 2 of my "styling stylesheets" article on DeveloperWorks
(http://www.ibm.com/xml); it includes a template which will generate a
PseudoXPath to a node. (I realized after publication that producing a
real, but slightly ugly XPath isn't that much harder if you use
predicates, but the editors didn't seem to have a way for me to go back
and tack that tip onto the article. Oh well.)

I suspect that XPath is a better solution for your needs... but at the
very least this will show you how to do the recursive counting needed to
build up your version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top