XSLT: Creating partly expanded navigation menu from full hierarchy

H

Harlan Messinger

I'm sure this is covered on the Web, but I can't figure out a
sufficiently narrow Google query: Suppose I have a hierarchical website
structure

Page 1
Page 1a
Page 1b
Page 1b1
Page 1b2
Page 1b3
Page 2
Page 2a
Page 2b
Page 2c
Page 3
Page 4
Page 4a
Page 4b

encapsulated in XML, where each node has an attribute called "item" and
one called "url". In a page on my web server (ASP, PHP, whatever) I have
a value that may match the item attribute belonging to one of my nodes.
This should allow me to display a navigation menu that shows only the
top-level items, except that every item that is an ancestor of the
current page or that IS the current page should be expanded. So if I'm
on page 1 or on page 1a, I should see the following items on the
navigation menu:

Page 1
Page 1a
Page 1b
Page 2
Page 3
Page 4

If I'm on page 1b or on any of its children, I should see

Page 1
Page 1a
Page 1b
Page 1b1
Page 1b2
Page 1b3
Page 2
Page 3
Page 4

If I'm on page 3 then I should only see:

Page 1
Page 2
Page 3
Page 4

One further detail: the item that matches the current page is the only
one that *shouldn't* be hyperlinked.

Can someone point me to an illustration of this?
 
P

Peyo

Harlan Messinger a écrit :
Can someone point me to an illustration of this?

Given your "context menu", and in a bottom-up approach, you want to
display the preceding siblings of its last ancestor, its ancestors, its
preceding siblings, it-self, its children (but not its other
descendants), its following siblings, then the following siblings of its
last ancestor. Many well-known XPath axes here ;-) and a subtility about
the definition of "last" ancestor...

Well, the best way to go is probably to use a top-down approach and to
process each menu recursively except if the menu isn't an ancestor of
the "context menu" or a sibling of its last ancestor, one if its
siblings (preceding and following, or, as a variant, a menu whose parent
it the same as the "context menu") or one of its children (but not its
descendants).
> One further detail: the item that matches the current page is the only
> one that *shouldn't* be hyperlinked.

You want a different processing if the processed "menu" is equal/not
equal to your "context menu".

Cheers,

p.b.
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top