Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Oct 29, 2012 @ 14:54
    Steve
    0

    Basic Node Refrence

    I am haveing a hard time grasping the basic concepts reguarding node selection in xpath. Here is my xml site structure:

    Content
    Business Site
    Company News (doctype = umbNewsArea)

    News Article 1 (doctype = NewsArticle) (property = featuredImage)
    News Article 2 (doctype = NewsArticle) (property = featuredImage)
    News Article 3 (doctype = NewsArticle) (property = featuredImage)

    I am trying to refrence the News Articles and select the "featuredImage" property from them to display in a slideshow. Here is my xslt:

    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <xsl:variable name="sliderNode" select="$currentPage/parent::*/child::node/data[@alias=umbNewsArea]"/>

    <div id="slider">
    <div id="imageSlider">
    <xsl:for-each select="$sliderNode/NewsArticle/featuredImage">
    <div class="imageSlide">
    <div class="imageSliderInfo">
    <h2> <xsl:value-of select="@nodeName"/></h2>
    <xsl:value-of select="teaserText" disable-output-escaping="yes"/>
    </div>
    <div class="imageSliderImage">
    <img src="{featuredImage}" width="500" height="320" />

     </div>
         </div>

     </xsl:for-each>
     </div>
    </div>

     

    </xsl:template>

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 29, 2012 @ 15:03
    Chriztian Steinmeier
    0

    Hi Steve,

    It just seems as if you've mixed some legacy schema XPath with some of the new (as of Umbraco 4.5.2 I think) easier schema - try this:

    <xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="ancestor-or-self::*[@level = 1]" />
    
    <xsl:template match="/">
        <xsl:variable name="sliderNode" select="$siteRoot/umbNewsArea"/>
    
        <div id="slider">
            <div id="imageSlider">
                <xsl:for-each select="$sliderNode/NewsArticle">
                    <div class="imageSlide">
                        <div class="imageSliderInfo">
                            <h2><xsl:value-of select="@nodeName"/></h2>
                            <xsl:value-of select="teaserText" disable-output-escaping="yes"/>
                        </div>
                        <div class="imageSliderImage">
                            <img src="{featuredImage}" width="500" height="320" />
                        </div>
                    </div>
                </xsl:for-each>
             </div>
        </div>
    </xsl:template>

    /Chriztian

  • Steve 472 posts 1216 karma points
    Oct 29, 2012 @ 15:14
    Steve
    0

    I guess what confuses me is <xsl:parm name="currentPage"/>. Where am I in the node tree when my xslt is called since I am using <xsl:template match="/">?

    I thought that would be at the top of my tree or in my case the node "Content". What basic concept about xpath am I missing?

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Oct 29, 2012 @ 15:19
    Dennis Aaen
    0

    Hi Steve.

    Chriztian has just make a little mistake, missing the $currentPage variable in the siteRoot variable.

    <xsl:variable name="siteRoot" select="ancestor-or-self::*[@level = 1]" />

    Try this instead

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

    Hope this can help you further.

    /Dennis

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 29, 2012 @ 15:22
    Chriztian Steinmeier
    0

    Hi Steve,

    Cool you ask that - almost no one does that :-)

    Check this Gist for an explanation of the way Umbraco provides the context (which at first seems a little strange if you're used to XML & XSLT, but it actually works pretty great for supplying just the context you usually need.)  

    /Chriztian

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 29, 2012 @ 15:24
    Chriztian Steinmeier
    0

    @Dennis: Well spotted, thanks! I'd edit the post if I had the balls, but I've already burned my fingers on that once today, so I'll leave it in :-)

    /Chriztian

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Oct 29, 2012 @ 15:34
    Dennis Aaen
    0

    @Chriztian Thanks a lot. I just spotted it :). You have helped me with some XSLT questions. You are a XSLT genes Chriztian. :)

     

  • Steve 472 posts 1216 karma points
    Oct 29, 2012 @ 15:50
    Steve
    0

    Chriztian,

    Thanks for the help! Still alittle confusing, but I'll get it. One problem though, my "featuredImage" from the doctype "NewsArticle" is showing as a broken link. I have the property type as "Media Picker",so they are selected within the "NewsArticle". What should I check? Did I refrence it incorrectly as

    <img src="{featuredImage}" width="500"height="320"/>

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 29, 2012 @ 16:07
    Chriztian Steinmeier
    0

    Oh yes, I was assuming an "Upload field" for that property.

    You'll just need to dig out the GetMedia() extension, I'd recommend using a separate template:

    <xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <xsl:template match="/">
        <xsl:variable name="sliderNode" select="$siteRoot/umbNewsArea"/>
    
        <div id="slider">
            <div id="imageSlider">
                <xsl:for-each select="$sliderNode/NewsArticle">
                    <div class="imageSlide">
                        <div class="imageSliderInfo">
                            <h2><xsl:value-of select="@nodeName"/></h2>
                            <xsl:value-of select="teaserText" disable-output-escaping="yes"/>
                        </div>
                        <div class="imageSliderImage">
                            <xsl:apply-templates select="featuredImage[normalize-space()]" />
                        </div>
                    </div>
                </xsl:for-each>
             </div>
        </div>
    </xsl:template>
    
    <xsl:template match="featuredImage">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" />
        <xsl:if test="not($mediaNode[error])">
            <img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" alt="{@nodeName}" />
        </xsl:if>
    </xsl:template>

    /Chriztian 

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 29, 2012 @ 16:09
    Chriztian Steinmeier
    0

    Oh man - I did it again :-)

    Here's that template again:

    <xsl:template match="featuredImage">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" />
        <xsl:if test="not($mediaNode[error])">
            <img src="{$mediaNode/umbracoFile}" width="{$mediaNode/umbracoWidth}" height="{$mediaNode/umbracoHeight}" alt="{$mediaNode/@nodeName}" />
        </xsl:if>
    </xsl:template>

    /Chriztian

  • Steve 472 posts 1216 karma points
    Oct 29, 2012 @ 16:34
    Steve
    0

    That did the trick! Question though, $mediaNode variable that you pull using GetMedia(). What value is it? is it the image itself? or a property that holds all the node data for the image? 

     

    <img src="{$mediaNode/umbracoFile}" width="{$mediaNode/umbracoWidth}" height="{$mediaNode/umbracoHeight}" alt="{$mediaNode/@nodeName}" />

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 29, 2012 @ 16:43
    Chriztian Steinmeier
    0

    It's a chunk of XML, much like the content XML doc - looks something like this:

    <Image id="1118" level="2" nodeName="Homeworld" urlName="homeworld" nodeTypeAlias="Image">
        <umbracoFile>/media/734/the_homeworld_by_microbot23.jpg</umbracoFile>
        <umbracoWidth>2000</umbracoWidth>
        <umbracoHeight>1486</umbracoHeight>
        <umbracoBytes>1620506</umbracoBytes>
        <umbracoExtension>jpg</umbracoExtension>
    </Image>

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies