Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Jun 20, 2013 @ 20:15
    Bjarne Fyrstenborg
    0

    Get data from nodes picked with MNTP

    I have a multilingual site structure like this:

    • Website
      • da
        • Forside (has property carouselCustomers (multinode tree picker))
        • ...
        • Kunder
          • Kunde
          • Kunde
          • Kunde
      • en
        • Frontpage (has property carouselCustomers (multinode tree picker))
        • ...
        • Customers
          • Customer
          • Customer
          • Customer

     

    I am then using multipicker helper to get the selected nodes.

    In my xslt I have the following code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:include href="multipicker-helper.xslt" />
    <xsl:param name="currentPage"/>
    
    <xsl:variable name="langNode" select="$currentPage/ancestor-or-self::Lang"/>
    
    <xsl:variable name="customer" select="$langNode//Customer[string(umbracoNaviHide) != '1']"/>
    <xsl:variable name="selectedCustomers" select="$langNode/Frontpage/carouselCustomers"/>
    
    <xsl:template match="/">
    
    <xsl:if test="normalize-space($selectedCustomers)">
    <div class="image_carousel">
        <div id="carousel">
          <xsl:apply-templates select="$selectedCustomers" mode="multipicker" />
        </div>
      <div class="clearfix"><xsl:text> </xsl:text></div>
      <a class="prev" id="prev" href="#"><span>prev</span></a>
      <a class="next" id="next" href="#"><span>next</span></a>
    </div>
    </xsl:if>
    
    </xsl:template>
    
    <xsl:template match="Customer">
        <!--<xsl:value-of select="@id" />-->
        <xsl:variable name="image" select="umbraco.library:GetMedia(customerLogo, 0)" />
    
        <xsl:if test="normalize-space(customerLogo)">
            <div class="item">
                <img src="{$image/umbracoFile}" class="customerLogo" alt="{@nodeName}" />
              </div>
        </xsl:if>
    </xsl:template>
    
    </xsl:stylesheet>

    When I use this code I also see the customer logos in the jQuery carousel, when I look at the Danish version of the site, but when I access the English version of the website I get Error parsing XSLT file: \xslt\customerCarousel.xslt

    I have tried in the template matching on Customer to only write:

    <xsl:template match="Customer">
        <xsl:value-of select="@id" />
    </xsl:template>
    

    which return a list of node ids which is different from each site language, because of different selected nodes in the structure.

    and with this line I get a list of the media ids, which in this case returns same media ids, because the content nodes have selected the same media items as image:

    <xsl:template match="Customer">
        <xsl:value-of select="customerLogo" />
    </xsl:template>
    

    But when I then try to get the media paths, it returns the image path in the Danish site version, but it fails on the English site version:

    <xsl:template match="Customer">
        <xsl:value-of select="umbraco.library:GetMedia(customerLogo, 0)" />
    </xsl:template>
    

    What am I doing wrong?

    /Bjarne

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Jun 20, 2013 @ 20:57
    Chriztian Steinmeier
    101

    Hi Bjarne,

    You're doing the right things, it seems - but there's one critical place where you seem to assume too much: You're not testing the customerLogo property before sending it into the GetMedia() method - my guess is that one of the Customer nodes in the English section has an empty customerLogo...

    You can just move the if statement up like this:

    <xsl:template match="Customer">
        <xsl:if test="normalize-space(customerLogo)">
            <xsl:variable name="image" select="umbraco.library:GetMedia(customerLogo, 0)" />
    
            <div class="item">
                <img src="{$image/umbracoFile}" class="customerLogo" alt="{@nodeName}" />
            </div>
        </xsl:if>
    </xsl:template>

    - or (my preferred version) - create a template to match those and "flag" them so you'll notice ("lime" is always good here :-)

    <!-- Standard Customer output -->
    <xsl:template match="Customer">
        <xsl:variable name="image" select="umbraco.library:GetMedia(customerLogo, 0)" />
    
        <div class="item">
            <img src="{$image/umbracoFile}" class="customerLogo" alt="{@nodeName}" />
        </div>
    </xsl:template>
    
    <!-- Template for Customer nodes with no customerLogo -->
    <xsl:template match="Customer[not(normalize-space(customerLogo))]">
        <div class="item" style="background: lime;">
            <xsl:comment>No customerLogo in Customer with id: <xsl:value-of select="@id" /> </xsl:comment>
        </div>
    </xsl:template>

    /Chriztian

  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Jun 20, 2013 @ 21:17
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    You are right :)
    One of the customer nodes in English section was missing the logo.. sorry about that :)

    Thanks for pointing on this ..  and for sharing the example above.. especially the last example might be useful as a fallback template.
    it works just fine now :)

    /Bjarne 

  • 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