Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : Getting a specific parent of any node via xpath navigation



darrel
10/31/2005 1:26:07 PM
I am storing my site structure as such:

<menuItems>
<menuItem>
<pageID>1</pageID>
</menuItem>
<menuItem>
<pageID>2</pageID>
<menuItem>
<pageID>4</pageID>
<menuItem>
<pageID>5</pageID>
<menuItem>
<pageID>6</pageID>
</menuItem>
</menuItem>
</menuItem>
</menuItem>
<menuItem>
<pageID>3</pageID>
</menuItem>
</menuItems>

I have two menus on my site. One is just the top-level items, and the other
is the sub-level items depending on which top-level item is selected.

The only variable I am passing is the pageID.

I want to be able to have my control see that if the page to display is '6',
then I need to show the subenu that starts at level 4.

What would the logic be? Right now, I'm thinking I'd need to pass an
expression to select the node 6, then I'd have to loop, moving up a level
each time until I reached the top-most level. Is there a better way or is
that type of looping just fine?

-Darrel

darrel
10/31/2005 5:31:21 PM
[quoted text, click to view]

Well, one node lower than the root node.

[quoted text, click to view]

It's not always the grandparent.

[quoted text, click to view]

I agree. I eventually realized that I need to do it from the other
direction. Pick the parent node that has any descendent matching what I'm
looking for.

-Darrel

Peter Flynn
10/31/2005 11:03:00 PM
[quoted text, click to view]

How is it to know what "the top-most level" is for any given pageID?
Is it always the grandparent? Or some other logic?

[quoted text, click to view]

Looping is almost certainly the wrong way. Give $page="6", then
the XPath statement pageID[.=$page]/parent::menuItem/parent::menuItem
will identify the grandparent.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
AddThis Social Bookmark Button