Copied to clipboard

Flag this post as spam?

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


  • Stefan 117 posts 215 karma points
    Oct 05, 2011 @ 00:16
    Stefan
    0

    Change the value of a variable

    Hi.

    I'm creating a gallery where I need to check the dimensions of the images from the mediafolder against each other, and then pass the value to ImageGen to generate the correct thumb sizes. The images will then be cropped (using jQuery) to make them look nice in the gallery.

    My solution will only work if I can pass the correct string to ImageGen based on the dimensions.

    Here's my approach:

      <xsl:variable name="mediaWidth" select="umbracoWidth"/>
    <xsl:variable name="mediaHeight" select="umbracoHeight"/>

    <xsl:if test="$mediaWidth > $mediaHeight">
    <xsl:variable name="mediaDimensions" select="'height=100'" />
    </xsl:if>

    <xsl:if test="$mediaHeight > $mediaWidth">
    <xsl:variable name="mediaDimensions" select="'width=100'" />
    </xsl:if>


    When the variables have been defined, I want to insert the value of the one variable in the string that generates the new image with ImageGen.

    <img>
    <xsl:attribute name="src">
    <xsl:text>/imageGen.ashx?image=</xsl:text>
    <xsl:value-of select="umbracoFile" />
    <xsl:text>&amp;</xsl:text>
    <xsl:value-of select="$mediaDimensions" />
    <xsl:text>&amp;constrain=true</xsl:text>
    </xsl:attribute>
    <xsl:attribute name="alt"><xsl:value-of select="@nodeName"/></xsl:attribute>
    <xsl:attribute name="class">galleryCrop</xsl:attribute>
    </img>


    After reading more about variables in XSLT, I've learned that it's not possible to change the value once it has been defined. Is it possible to do as I'm trying, or is there a clever solution to the problem?

    Thanks in advance for your help!
    Stefan.

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 05, 2011 @ 00:28
    Chriztian Steinmeier
    0

    Hi Stefan,

    You can "open" the variable declaration and use choose/when/otherwise to determine the result:

    <xsl:variable name="mediaWidth" select="umbracoWidth"/>
    <xsl:variable name="mediaHeight" select="umbracoHeight"/>
    
    <xsl:variable name="mediaDimensions">
        <xsl:choose>
            <xsl:when test="$mediaWidth &gt; $mediaHeight">height=100</xsl:when>
            <xsl:otherwise>width=100</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    /Chriztian

  • Rodion Novoselov 694 posts 859 karma points
    Oct 05, 2011 @ 01:07
    Rodion Novoselov
    0

    What if try this:

    <img>
     
    <xsl:attributename="src">
           
    <xsl:text>/imageGen.ashx?image=</xsl:text>
           
    <xsl:value-ofselect="umbracoFile"/>
           
    <xsl:text>&amp;</xsl:text>
    <xsl:text>width=</xsl:text>
           
    <xsl:value-ofselect="100 * umbracoWidth / max((umbracoWidth, umbracoHeight))"/>
    <xsl:text>&amp;</xsl:text>
    <xsl:text>height=</xsl:text>
    <xsl:value-ofselect="100 * umbracoHeight / max((umbracoWidth, umbracoHeight))"/>
           
    <xsl:text>&amp;constrain=true</xsl:text>
     
    </xsl:attribute>
     
    <xsl:attributename="alt"><xsl:value-ofselect="@nodeName"/></xsl:attribute>
     
    <xsl:attributename="class">galleryCrop</xsl:attribute>          
    </img>

    (I didn't try it on my own, however - not sure it will work)

  • Stefan 117 posts 215 karma points
    Oct 05, 2011 @ 01:38
    Stefan
    0

    Thank you (again) so much! That works like a charm :-)
    One can really learn from this forum!

    Btw, I have a strange problem when fetching the images for the gallery.
    The first entry generates a "Hello World" image with ImageGen,
    because it cannot find the specific file.

    Look at this output:

    <Image id="1208" version="58c752a4-78f7-4ce5-9e00-0a5b096b7b2e" 
    parentID="1207" level="3" writerID="0" nodeType="1032" template="0"
    sortOrder="1" createDate="2011-10-03T22:42:33"
    updateDate="2011-10-03T22:42:33" nodeName="0149015991003(2).jpg"
    urlName="0149015991003(2).jpg" writerName="Stefan"
    nodeTypeAlias="Image" path="-1,1175,1207,1208">
    <umbracoFile />
    <umbracoWidth>400</umbracoWidth>
    <umbracoHeight>300</umbracoHeight>
    <umbracoBytes>21573</umbracoBytes>
    <umbracoExtension>jpg</umbracoExtension>
    </Image>

    <Image id="1209" version="e51299cb-6b4d-4d96-be0f-b7466dd6614b"
    parentID="1207" level="3" writerID="0" nodeType="1032" template="0"
    sortOrder="2" createDate="2011-10-03T22:42:33"
    updateDate="2011-10-03T22:42:33" nodeName="2805098396_43241402db_b.jpg"
    urlName="2805098396_43241402db_b.jpg" writerName="Stefan"
    nodeTypeAlias="Image" path="-1,1175,1207,1209">
    <umbracoFile>/media/640/2805098396_43241402db_b.jpg</umbracoFile>
    <umbracoWidth>1024</umbracoWidth>
    <umbracoHeight>815</umbracoHeight>
    <umbracoBytes>325338</umbracoBytes>
    <umbracoExtension>jpg</umbracoExtension></Image>


    I had trouble with a image not showing correctly, I then deleted it.
    It's like it's still there in the cache or something.

    I have already refreshed the XML cache, but that didn't do the trick.

    Any clues?

  • Rodion Novoselov 694 posts 859 karma points
    Oct 05, 2011 @ 06:33
    Rodion Novoselov
    0

    It looks like there's an existing media item in the media library (with id="1208") but it has no file uploaded. Try to go to the media section of the backoffice and upload an image to this entry again. (If everything is ok there'll be some path like /media/bla-bla-bla inside <umbracoFile> tag after this - currently you can see that it's empty)

  • Stefan 117 posts 215 karma points
    Oct 05, 2011 @ 09:55
    Stefan
    0

    Thank you. That did the trick!

Please Sign in or register to post replies

Write your reply to:

Draft