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 1284 posts 4038 karma points MVP 8x c-trib
    Jul 24, 2011 @ 14:03
    Bjarne Fyrstenborg
    0

    File size of images with umbracoBytes

    Hi..

    I have listed up images from a folder and trying to show the file size of an image on hover, but I seem that I get the same media id and therefore also the same size is shown.
    You can see an example here: http://fonnesberg.com/en/press/download/photos.aspx

    Someone who can see what I am missing?

    <?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:param name="currentPage"/>

    <xsl:variable name="imageRoot" select="$currentPage/photos"/>
    <xsl:variable name="mediaId" select="number($currentPage/photos)"/>
    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, true())/*"/>

    <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($mediaId, true())"/>
        
    <xsl:variable name="itemsPerPage" select="20"/>
    <xsl:variable name="numberOfItems" select="count($mediaItems//Image)"/>

    <xsl:variable name="pageNumber">
      <xsl:choose>
        <xsl:when test="umbraco.library:RequestQueryString('page') = ''">
          <xsl:value-of select="1"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">

    <xsl:variable name="size" select="$media/umbracoBytes" />
    <xsl:variable name="sizeAndSuffix">
            <xsl:choose>
                    <xsl:when test="$size &gt;= 1073741824">
                            <xsl:value-of select="format-number($size div 1073741824,'#,###')"/>
                            <xsl:textGB</xsl:text>
                    </xsl:when>
                    <xsl:when test="$size &gt;= 1048576">
                            <xsl:value-of select="format-number($size div 1048576,'#,###')"/>
                            <xsl:textMB</xsl:text>
                    </xsl:when>
                    <xsl:when test="$size &gt;= 1024">
                            <xsl:value-of select="format-number($size div 1024,'#,###')"/>
                            <xsl:textKB</xsl:text>
                    </xsl:when>
                    <xsl:when test="$size &gt; 0 and $size &lt; 1024">
                            <xsl:value-of select="format-number($size div 0,'#,###')"/>
                            <xsl:textBytes</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                            <xsl:text>0 Bytes</xsl:text>
                    </xsl:otherwise>
            </xsl:choose>
    </xsl:variable>

    <xsl:if test="string-length($imageRoot) &gt; 0">
       <xsl:for-each select="$mediaItems//Image">
        <xsl:if test="position() &gt; $itemsPerPage * number($pageNumber -1) and
    position() &lt;= number($itemsPerPage * number($pageNumber -1) + $itemsPerPage)">
        
        <href="{umbracoFile}" title="{@nodeName} - {$sizeAndSuffix}" target="_blank">
          <img src="{concat(substring-before(umbracoFile,'.'),'_thumb_90.jpg')}" height="90" width="90" class="download_photo" />
        </a>
        </xsl:if>
      </xsl:for-each>
    </xsl:if>

    <xsl:if test="$numberOfItems &gt; $itemsPerPage">
    <div id="paging">
    <xsl:if test="$pageNumber &gt; 1">
      <class="previous" href="?page={$pageNumber -1}">&#8249;</a>
    </xsl:if>

    <xsl:call-template name="for.loop">
      <xsl:with-param name="i">1</xsl:with-param>
      <xsl:with-param name="count" select="ceiling($numberOfItems div $itemsPerPage)"></xsl:with-param>
    </xsl:call-template>


    <xsl:if test="(($pageNumber) * $itemsPerPage) &lt; ($numberOfItems)">
      <class="next" href="?page={$pageNumber +1}">&#8250;</a>
    </xsl:if>
    </div>
    </xsl:if>

    </xsl:template>

    <xsl:template name="for.loop">
                    <xsl:param name="i"/>
                    <xsl:param name="count"/>
                    
                    <xsl:if test="$i &lt;= $count">
          
                            <xsl:if test="$pageNumber != $i">
                                    <class="pageitem" href="?page={$i}">
                                            <xsl:value-of select="$i" />
                                    </a>
                            </xsl:if>

                            <xsl:if test="$pageNumber = $i ">
          
          <span class="currentpageitem">
                                     <xsl:value-of select="$i" />
          </span>
                            </xsl:if>

                            <xsl:call-template name="for.loop">
                                    <xsl:with-param name="i" select="$i + 1" />
                                    <xsl:with-param name="count" select="$count">
                                    </xsl:with-param>
                            </xsl:call-template>
                    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>

    Bjarne

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 25, 2011 @ 07:51
    Dirk De Grave
    0

    Hi Bjarne,

    you need to move your two variables size and sizeAndSuffix into your for-each loop that iteraties your images from. Currently, you're only getting the value once for the folder, which doesn't have this property.

    <xsl:for-each select="$mediaItems//Image">
        <xsl:if test="position() &gt; $itemsPerPage * number($pageNumber -1) and
    position() &lt;= number($itemsPerPage * number($pageNumber -1) + $itemsPerPage)">
        <xsl:variable name="size" select="./umbracoBytes" />
        <xsl:variable name="sizeAndSuffix">...</xsl:variable>
        <a href="{umbracoFile}" title="{@nodeName} - {$sizeAndSuffix}" target="_blank">
          <img src="{concat(substring-before(umbracoFile,'.'),'_thumb_90.jpg')}" height="90" width="90" class="download_photo" />
        </a>
        </xsl:if>
      </xsl:for-each>

     

     

     

    Cheers,

    /Dirk

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jul 25, 2011 @ 13:42
    Bjarne Fyrstenborg
    0

    Hi Dirk

    Thanks for your answer.
    I had tried that before, but it didn't seem to make a difference.

    As you can see on the image, I get the same id 1869 which is the id of my folder.
    I think it's because the mediaId is outside the loop, and it's just the id of the folder I picked.

    So if I use ./umbracoBytes instead of $media/umbracoBytes I get the filesize of each image. Before I get 11 MB, so I think it only was the first image I get.

    But I am not sure how to get the mediaId for each image?

     

    I have changes the format of filesize to have to decimals:

    <xsl:when test="$size &gt;= 1048576">
        <xsl:value-of select="format-number($size div 1048576,'#,###.##')"/>
        <xsl:textMB</xsl:text>
    </xsl:when>

     

    so the '#,###' to '#,###.##'  ... do you know how to use comma instead?

    Bjarne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jul 25, 2011 @ 13:52
    Bjarne Fyrstenborg
    0

    Hmm... the images don't seem to be inserted correctly..

    But you can see them when you enter our.umbraco.org in front of the url..

Please Sign in or register to post replies

Write your reply to:

Draft