Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Claushingebjerg 939 posts 2574 karma points
    Oct 06, 2010 @ 12:25
    Claushingebjerg
    0

    ancestor-or-self starts from level 0 ?

    I havv the following xslt

    <xsl:value-of select="$currentPage/ancestor-or-self::*[@isDoc]/flashfil"/>

     

    What im trying to do is render the value of the document type parameter "flashfil", if it is set on the current page.If it is not set on the current page, i would like to check the parent node. And so on.

    "Flashfil" is a radio button list with 2 options, which should return either 12 or 13

    The above does'nt work. If my root node has "flashfil" set, the value is inherited down through all nodes.

    It seems like it checks from level0 and downwoards and not from the current page and upwards...

    Am i doing something wrong?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 06, 2010 @ 13:40
    Chriztian Steinmeier
    0

    Hi Claus,

    Try this:

    <xsl:value-of select="$currentPage/ancestor-or-self::*[@isDoc][normalize-space(flashfil)][1]/flashfil" />

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Oct 06, 2010 @ 13:45
    Claushingebjerg
    0

    Thanks that works.

    Could you elaborate at bit about the difference, and why one works and the other does'nt?

    Maybe just a link to an article about it. Im really trying to get a hang of 4.5 schema, but its not always as simple as it seems...

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 06, 2010 @ 14:08
    Chriztian Steinmeier
    0

    Of course :-)

    I explained this in a previous post by @cultiv but I can't find it right now, so here goes a shorter version: 

    Whenever you do select in XPath, you get a set of nodes back - so your version will return 1, 2, 3 or more <flashfil> nodes. When you use value-of (or another function that returns a string) it will always take its value from the first node that matches.

    The way the solution works is this:

    "Select the ancestors (or current) that is a document node that doesn't have an empty "flashfil" property - take the first of those and return its flashfil property"

    One tricky part is knowing that when you use the predicate [1] inside the expression, it matches the first node above $currentPage, but if you were to use it afterwards, it would match the topmost...

    Hope that helps,

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft