Copied to clipboard

Flag this post as spam?

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


  • Jules 276 posts 587 karma points
    May 10, 2011 @ 10:44
    Jules
    0

    Get parent node when child is empty

    Hi all

    I have the following 

    <xsl:template match="/">

        <img>

            <xsl:attribute name="src">

              <xsl:value-of select="umbraco.library:GetMedia($currentPage/bannerImage, 'false')/umbracoFile" />      

            </xsl:attribute>

        </img>

    </xsl:template>

    However this only works if the currentpage has a bannerImage.

    I need this get the bannerImage from the parent if the child page does not have anything in bannerImage

    Thanks

    J

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 10, 2011 @ 14:28
    Chriztian Steinmeier
    1

    Hi juliang,

    Here's the XSLT equivalent of the "recursive" option for properties:

    <xsl:template match="/">
        <xsl:variable name="bannerImage" select="$currentPage/ancestor-or-self::*[normalize-space(bannerImage)][1]/bannerImage" />
        <xsl:if test="$bannerImage">
            <img src="{umbraco.library:GetMedia($bannerImage, false())/umbracoFile}" />
        </xsl:if>
    </xsl:template>

    /Chriztian

  • Jules 276 posts 587 karma points
    May 10, 2011 @ 14:51
    Jules
    0

    Great!

    I had managed to workaround it but very inefficienly. Still feeling my way with xslt

    Thanks a lot

    Julian

  • FarmFreshCode 225 posts 422 karma points
    May 10, 2011 @ 15:04
    FarmFreshCode
    0

    @Chriztian

    Hi, I'm looking to do something similar with a "recursive" value (see code below)

    <xsl:if test="$currentPage/youTubeHide != '1'">
      <iframe width="287" height="215" >
      <xsl:attribute name="src">http://www.youtube.com/embed/<xsl:value-of select="$currentPage/youTubeURL" />?fs=0;autohide=1</xsl:attribute>
      </iframe
    </xsl:if>

    I haven't been able to change my "$currentPage/youTubeURL" into something that (if empty) will look to the parent for a value. Should I be writing something like your solution above? Im using 4.7

  • Petr Snobelt 923 posts 1535 karma points
    May 10, 2011 @ 16:22
    Petr Snobelt
    0

    See this old, but still great post about recursion in xslt

    http://forum.umbraco.org/yaf_postst2751_XSLT-Tip--Display-a-field-recursively.aspx

    Petr

     

  • FarmFreshCode 225 posts 422 karma points
    May 10, 2011 @ 16:58
    FarmFreshCode
    0

    @Petr - yeah I was looking at that article earlier, but I'm pretty sure that's based on the old scheme which doesn't work for me since Im using 4.7

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

    Seems to be closer to the answer that I am looking for.. but I havent gotten quite working to pull info from from my home node if a child node hasn't provided its own info..

  • FarmFreshCode 225 posts 422 karma points
    May 10, 2011 @ 21:12
    FarmFreshCode
    0

    Ok solved.. it required that I re-publish all of the pages for the change to take effect but my final solution is as follows:

    <iframe width="320" height="240" >
      <xsl:attribute name="src">http://www.youtube.com/embed/<xsl:value-of select="$currentPage/ancestor-or-self::*[youTubeURL[normalize-space()]][1]/youTubeURL" />?fs=0;autohide=1</xsl:attribute>
      </iframe>

    Just want to give thanks to Chriztian Steinmeier , between this post and some others by him I was able to get this knocked out. Probably a lot sooner if I had figured out I needed to republish everyting.. but oh well.. new troubleshooting lesson learned.

Please Sign in or register to post replies

Write your reply to:

Draft