XSLT question ancestor-or-self::


I am trying some XSLT code. O don't get to seem the ancestor-or-self:: working. Can anyone tell me why this is not working. I also have a similar XSLT in Umbraco but the the param currentPage is filled as a param and I am filling it with a XML file.

<?xml version="1.0" encoding="UTF-8"?>

  <xsl:output method="xml" omit-xml-declaration="yes" />

  <!--<xsl:param name="currentPage"/> -->
  <!-- Input the documenttype you want here -->
  <xsl:variable name="level" select="1"/>

  <xsl:template match="/">    
    <xsl:variable name="currentPage" select="/"/>

    <!-- The fun starts here -->
    <ul id="topnavigation">
      <xsl:for-each select="$currentPage/ancestor-or-self::node[@level=$level]/node[string(data [@alias='umbracoNaviHide']) != '1']">
          <a href="#">
            <xsl:value-of select="@nodeName"/>



XML file is  attached

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
it seems to work for me
of course ancestor is looking up the tree,
if you make $currentPage select="/", there is not much looking up

- I suggest that you pass in the id of the node as a parameter, not the node itself
<xsl:param name="cur-page-id"/>

I checked whether it was working with this
        <xsl:variable name="currentPage" select="//node[@id='1050']"/>
and it does
passing in the id it would be something like this
        <xsl:variable name="currentPage" select="//node[@id=$cur-page-id]"/>

If your XML becomes really big, I would use a key instead of the //node

Please note that you are looking up the tree, using ancestor-or-self::node, but from there you go back down,
so you are not necessarily building a full navigation trace
you are listing all the level 2 nodes that are child of the ancestor level 1 node (level being a parameter as well)
and that are not indicated as "hidden"
<xsl:for-each select="$currentPage/ancestor-or-self::node[@level=$level]/node[not(data[@alias='umbracoNaviHide'] = '1')]">

so if that is what you want to do, it seems to work just fine, given the parameter binding is correct
that can be assured by passing the id instead of the node itself

vriendelijke groeten,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
waaromiknietAuthor Commented:
Hello Geert,

Thanks for the input. I still don't exactly get why

 <xsl:variable name="currentPage" select="/"/>

Is not working for me. When writing the param to screen as is comes from umbraco gives me the same XML als my attached file. So it seems to be working from Umbraco but not with a xml file.
waaromiknietAuthor Commented:

I used descendant-or-self::node
Na dno it is working for me. Thanks.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Geert BormansInformation ArchitectCommented:
well, if you really want it to work from top down,
you need descendant-or-self::*
short form would be "$currentPage//*"
by the way

Could have spotted that; I really thought you needed a bottom up approach
waaromiknietAuthor Commented:
With bottom up I first need to select a node lower in the tree right?
Why would I choose a bottom up approach? Or am I looking at it in a wrong way?
Geert BormansInformation ArchitectCommented:
I think I misjudged the goal of your question.
Since you were going bottom up, I guessed you were building a breadcrump.
That is when you would use a bottom up, to list the navigation path up to this particular point.

Now I see that you are just making a navigation list, from the point you are at, deeper down the hierarchy.
If that is the case, you should navigate downwards

I was put on the wrong foot by your usage of the ancestor axis
waaromiknietAuthor Commented:
If you start in the first template:

  <xsl:template match="/">    

You always start at the top right? If you want to start from the bottom yopu have to select the last node? and then work your way up?
Geert BormansInformation ArchitectCommented:
logically XSLT should always start working form the top, that is a natural way of processing a document

Most of the stylesheets start with a <xsl:template match="/">    (in XSLT1 they actually all do)
and so start from top of document

I have a feeling that I really confused you.

I thought you needed a breadcrump, given the context of a specific node.
That is something you would need if you were making a site from this one page, only showing one specific node from the XML in a page
If that were the case, you would have a starting point, right in the middle of your document, making all the implicit navigation explicit
waaromiknietAuthor Commented:
Thanks for your help
Geert BormansInformation ArchitectCommented:
Geert BormansInformation ArchitectCommented:
I think you have been assisted enough, no?
Geert BormansInformation ArchitectCommented:
I think you have been assisted enough, no?
Geert BormansInformation ArchitectCommented:
The original question was asking
"don't get to seem the ancestor-or-self:: working"

http:#a28430008 explains the ancestor-or-self behaviour
from that explanation the questioner realises he needed a different approach
that particular exposee seems valuable enough for a PAQ
so I suggest excepting http:#a28430008 as the answer

waaromiknietAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.