Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Dmitrij Jazel 86 posts 179 karma points
    Aug 01, 2012 @ 23:56
    Dmitrij Jazel
    0

    Problem retrieving Category image from Media

     

    Hello guys,

    I am trying to retrieve the Category thubnail image so that when I am listing the list of categories, I could see the category image along with category name :-) can't be clear as that...

    Here is my current XSLT file - that is actually the same RootCategories[xslt] file from the test shop... I just decided to extend it a bit...

    <?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:CommerceLibrary="urn:CommerceLibrary"
      exclude-result-prefixes="msxml umbraco.library CommerceLibrary">
    
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
      <xsl:variable name="catalogName" select="umbraco.library:RequestQueryString('catalog')"/>
      <xsl:variable name="categories" select="CommerceLibrary:GetRootCategories($catalogName)"/>
    
    <!-- start writing XSLT -->
      <ul>
        <xsl:for-each select="$categories/categories/category[@displayOnSite='True']">
          <li>
            <a>
              <xsl:attribute name="href">
          <xsl:value-of select="CommerceLibrary:GetNiceUrlForCategory($catalogName, @id)"/>
              </xsl:attribute>
              <xsl:value-of select="@displayName"/>
            </a>
    
              Media mode value: <xsl:value-of select="@image"/>
    
              <img alt="Image">
                <xsl:attribute name="src">
                    <xsl:value-of select="umbraco.library:GetMedia(@image, true())/umbracoFile"/>
                </xsl:attribute>
              </img>        
    
          </li>
        </xsl:for-each>
      </ul>
    
    </xsl:template>
    
    </xsl:stylesheet>

    Eventually I get Error parsing xslt file eventually, and that has something to do how I "feed" the media @image here:

    <xsl:value-of select="umbraco.library:GetMedia(@image, true())/umbracoFile"/> 

    cause it works fine if I hardcode node id that I getlike this:

     

    <xsl:value-of select="umbraco.library:GetMedia(1091, true())/umbracoFile"/>

     

    Where 1091 is my media image file.

    Can I please get some help here? :-)

     

     

    Regards,

    Dmitrij

  • Jordy Vialoux 73 posts 103 karma points
    Aug 02, 2012 @ 00:12
    Jordy Vialoux
    0

    Delete your code from "media mode value" down to the closing "img" tag and replace with this:

            <xsl:if test="articleThumb > 0">
              <xsl:variable name="img" select="umbraco.library:GetMedia(articleThumb, 0)" />
              <xsl:variable name="imgPath" select="concat(substring-before($img/umbracoFile,'.'), '.jpg')" />
              <img class="thumb-image" src="/ImageGen.ashx?image={$imgPath}&width=150&" alt="{@nodeName}" />
            xsl:if> 

    where you see "articleThumb" insert the generic property you want the image to pick up.

    Install image gen and set the resize width to what ever you like at the end of the image path.

    Let me know if you have any issues 

  • Søren Spelling Lund 1797 posts 2786 karma points
    Aug 07, 2012 @ 10:32
    Søren Spelling Lund
    0

    Does it work in some cases or not at all? It might be that some categories don't have an image set, which might cause the Umbraco API to fail.

  • Dmitrij Jazel 86 posts 179 karma points
    Aug 21, 2012 @ 23:41
    Dmitrij Jazel
    0

    Hello Guys,

    Sorry for late response, was on hollidays, just got back :-)

    Well not sure where am I making error here, but I am getting XSLT error message in the front-end.

    <?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:CommerceLibrary="urn:CommerceLibrary"
      exclude-result-prefixes="msxml umbraco.library CommerceLibrary">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

      <xsl:variable name="catalogName" select="umbraco.library:RequestQueryString('catalog')"/>
      <xsl:variable name="categories" select="CommerceLibrary:GetRootCategories($catalogName)"/>
      
    <!-- start writing XSLT -->
      <ul>
        <xsl:for-each select="$categories/categories/category[@displayOnSite='True']">
          <li>
            <a>
              <xsl:attribute name="href">
          <xsl:value-of select="CommerceLibrary:GetNiceUrlForCategory($catalogName, @id)"/>
              </xsl:attribute>
              <xsl:value-of select="@displayName"/>
            </a>

            <xsl:if test="articleThumb > 0">
              <xsl:variable name="img" select="umbraco.library:GetMedia(articleThumb, 0)" />
              <xsl:variable name="imgPath" select="concat(substring-before($img/umbracoFile,'.'), '.jpg')" />
              <img class="thumb-image" src="/ImageGen.ashx?image={$imgPath}&width=150&" alt="{@nodeName}" />
            </xsl:if>        
            
          </li>
        </xsl:for-each>
      </ul>
      
    </xsl:template>

    </xsl:stylesheet>

    Umbraco XSLT parser complains "System.Xml.XmlException: '=' is an unexpected token. The expected token is ';'. Line 35, position 78. " if I am saving it without skipping test. Could someone please correct me here if possible? :)

    Regards,

    Dmitrij

  • Dmitrij Jazel 86 posts 179 karma points
    Aug 22, 2012 @ 20:24
    Dmitrij Jazel
    0

    Anyone? :(

  • Jordy Vialoux 73 posts 103 karma points
    Aug 22, 2012 @ 23:26
    Jordy Vialoux
    0

    Hi Dmitrij,

    What version of umbraco are you using? 

    I am using umbraco 4.7.2 and have copied your xslt into a blank xslt file on my end and I'm getting an error  regarding: "exclude-result-prefixes="msxml umbraco.library CommerceLibrary""

    I have no idea what this is about but anyway here is the code to just get the image - the rest you can tweak or do what ever you like with: 

    <?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" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <ul>
      <xsl:for-each select="$currentPage">
        <li>
          <xsl:if test="articleThumb &gt; 0">
            <xsl:variable name="img" select="umbraco.library:GetMedia(articleThumb, 0)" />
            <xsl:variable name="imgPath" select="concat(substring-before($img/umbracoFile,'.'), '.jpg')" />
            <img class="person-image" src="/ImageGen.ashx?image={$imgPath}&amp;width=150&amp;" alt="{@nodeName}" />
          </xsl:if>
        </li>
      </xsl:for-each>
    </ul>
      
    </xsl:template>

    </xsl:stylesheet>

    Add your variables to the for-each to select where ever you want it to point to. Change the "articleThumb" to the alias of the image upload generic property on your doc type for the image to render. Also make sure you have Image Gen package installed otherwise this will not work!

    Jordy

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Aug 29, 2012 @ 10:06
    Søren Spelling Lund
    0

    @Dmitrij: It's the XSLT parser that can't figure out the URL provided for the "person-image". Specifically it's the & sign that messes with it.

    You want to out the escaped ampersand value instead:

    /ImageGen.ashx?image={$imgPath}&amp;width=150

    becomes

    /ImageGen.ashx?image={$imgPath}&amp;width=150&amp;

    Hope this helps.

     

  • Dmitrij Jazel 86 posts 179 karma points
    Sep 02, 2012 @ 20:31
    Dmitrij Jazel
    1

    Hej Guys,

    Sorry for long response again... But thanks for help so far :-)

    My Umbraco version is 4.7.2. Unfortunetly your examples didn't do the trick... but after tewaking a bit arround got an example that works for me :-) can't be more happy. I must still say thanks alot for help guys :-)

    My example here:

    <?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:CommerceLibrary="urn:CommerceLibrary"
      exclude-result-prefixes="msxml umbraco.library CommerceLibrary">


    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">

      <xsl:variable name="catalogName" select="umbraco.library:RequestQueryString('catalog')"/>
      <xsl:variable name="categories" select="CommerceLibrary:GetRootCategories($catalogName)"/>
      
    <!-- start writing XSLT -->
      <ul>
        <xsl:for-each select="$categories/categories/category[@displayOnSite='True']">
          <li>
            <xsl:if test="@image &gt; 0">
            <xsl:variable name="media" select="umbraco.library:GetMedia(@image, 0)" />
            <img src="{$media/umbracoFile}" alt="{@nodeName}" />
            </xsl:if>
          </li>
        </xsl:for-each>
      </ul>
      
    </xsl:template>
    </xsl:stylesheet>

    Kind regards,

    Dmitrij

Please Sign in or register to post replies

Write your reply to:

Draft