Link to home
Start Free TrialLog in
Avatar of waaromikniet
waaromiknietFlag for Netherlands

asked on

XSLT question ancestor-or-self::

Hello,

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:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt">

  <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']">
        <li>
          Item
          <a href="#">
            <xsl:value-of select="@nodeName"/>
          </a>
        </li>
      </xsl:for-each>
    </ul>

  </xsl:template>

</xsl:stylesheet>


XML file is  attached

Thanks in advance
Danny
test.xml
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of waaromikniet

ASKER

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.
Geert,

I used descendant-or-self::node
Na dno it is working for me. Thanks.
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
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?
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
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?
correct.
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
Thanks for your help
I think you have been assisted enough, no?
I think you have been assisted enough, no?
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


none