Copied to clipboard

Flag this post as spam?

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


  • AValor 32 posts 56 karma points
    Mar 03, 2011 @ 17:29
    AValor
    0

    Get a property from the first child

    Hi! I'm creating a xslt that takes one property from the page itself, and if it's not set, searches for that property in its first child...

    I got this, but seems to be wrong:

    <xsl:variable name="situacionGMaps">
    <xsl:choose>
    <xsl:when test="string($currentPage/situacionGMaps)!=''">
       <xsl:value-of select="string($currentPage/situacionGMaps)"/>
    </xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="$currentPage/child::*[@isDoc and string(umbracoNaviHide) != '1'][0]/situacionGMaps" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    What am I missing? (Umbraco 4.6.1)

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 03, 2011 @ 20:49
    Kim Andersen
    0

    Hi AValor.

    Could you try this:

    <xsl:variable name="situacionGMaps">
    <xsl:choose>
    <xsl:when test="$currentPage/situacionGMaps !=''">
       
    <xsl:value-of select="$currentPage/situacionGMaps"/>
    </xsl:when>
    <xsl:otherwise>
       
    <xsl:value-of select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']/situacionGMaps" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    Does that help?

    /Kim A

  • AValor 32 posts 56 karma points
    Mar 04, 2011 @ 09:47
    AValor
    0

    Thank you so much! It worked like a charm!

    I'm new in all this Umbraco universe and still get confused about understanding and building XPATH strings...

  • AValor 32 posts 56 karma points
    Mar 04, 2011 @ 09:49
    AValor
    0

    By the way, where I can get info about the new XSLT schema? I'm getting crazy mixing documentation about xlst and not knowing if it's valid or not...

    For example, I don't understand why $currentPage/* gets the first child...

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 04, 2011 @ 09:58
    Kim Andersen
    0

    Great to hear!

    You can see the following wiki entry on a little more info on the new XML schema: http://our.umbraco.org/wiki/reference/xslt/45-xml-schema

    $currentPage/*[@isDoc] gets the first node as it's just going down the levels until it finds what we are looking for and then stops. But notice that you can also use this selection in a for-each like this:

    <xsl:for-each select="$currentPage/*[@isDoc]">

    Which would run through each of the childnodes under the current page.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft