Copied to clipboard

Flag this post as spam?

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


  • Kevin Walker 66 posts 87 karma points
    Feb 21, 2011 @ 11:13
    Kevin Walker
    0

    XSLT Variable for folder number

    Given the following code Im using for a photo gallery, when I try to use my $folder variable instead of the folder number '1329' then I get the XSLT error below. I have very little experience with XSLT so if anyone can point me in the right direction it will be greatly appreciated.

    'System.OverflowException: Value was either too large or too small for an Int32.'

    <?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:variable name="folder" select="/macro/folder"/>
    <xsl:template match="/">
    <!-- start writing XSLT -->
    <xsl:for-each select="umbraco.library:GetMedia(1329, 1)/Image">
          <li>
            <a class="image" rel="lightbox">
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:GetMedia(@id, 0)/umbracoFile"/>
              </xsl:attribute>
              <img>
                  <xsl:attribute name="src">
                    <xsl:value-of select="umbraco.library:Replace(umbraco.library:GetMedia(@id, 0)/umbracoFile, '.', '_thumb.')"/>            
                  </xsl:attribute>
              </img>        
        </a>
         </li>
      </xsl:for-each>
    
    </xsl:template>
    
    </xsl:stylesheet>
  • kows 81 posts 151 karma points c-trib
    Feb 21, 2011 @ 12:18
    kows
    0

    you're selecting folder, shouldn't you be select /@id on it aswell?

    as it seems now i think you're putting the whole xml of folder in the variable..

  • Kevin Walker 66 posts 87 karma points
    Feb 21, 2011 @ 12:32
    Kevin Walker
    0

    Thanks for the reply kows.

    Do you mean when I am selecting the variable ie

    <xsl:variable name="folder" select="/macro/folder/@id"/>
    I have tried this but the same XSLT error is still occuring

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 21, 2011 @ 12:43
    Kim Andersen
    0

    Hi Kevin

    Could you try putting an xsl:if around the for-each? Something like this:

    <xsl:if test="$folder != ''">
    <xsl:for-each
    select="umbraco.library:GetMedia($folder, 1)/Image">
         
    <li>
           
    <a class="image" rel="lightbox">
             
    <xsl:attribute name="href">
               
    <xsl:value-of select="umbraco.library:GetMedia(@id, 0)/umbracoFile"/>
             
    </xsl:attribute>
             
    <img>
                 
    <xsl:attribute name="src">
                   
    <xsl:value-of select="umbraco.library:Replace(umbraco.library:GetMedia(@id, 0)/umbracoFile, '.', '_thumb.')"/>            
                 
    </xsl:attribute>
             
    </img>        
           
    </a>
         
    </li>
     
    </xsl:for-each>
    </xsl:if>

    /Kim A

  • Kevin Walker 66 posts 87 karma points
    Feb 21, 2011 @ 15:31
    Kevin Walker
    0

    <xsl:template match="/">
    <xsl:variable name="folder" select="/macro/folder/node/@id"/>
    <xsl:value-of select="$folder"/> 
    </xsl:template>
    </xsl:stylesheet>

    The following code above will not even return the id of the media folder. Am I missing something vital here? I have a parameter on my PhotoGallery macro called 'Folder' with an alias of 'folder' and a type of 'mediaCurrent'.

    Any help greatly appreciated.

     

  • kows 81 posts 151 karma points c-trib
    Feb 21, 2011 @ 15:40
    kows
    0

    what is your structure actually looking like?

    you're trying to select a property of a macro by xslt?

    dont think that's even possible oO

  • Kevin Walker 66 posts 87 karma points
    Feb 21, 2011 @ 15:49
    Kevin Walker
    0

    What structure do you wish to see sorry Im not sure?

    My basic problem is that I wish to have a number of photo galleries. Each using the same XSLT file to display the gallery so I can have a photo gallery on a page that maps to a folder in the Media area. I can get the images to come through when I hard code a folder id but I need the folder id to be dynamic in the PhotoGalleryXSLT or otherwise I would have to have an XSLT file for each gallery, as each gallery would need to refer to a different folder from the Media area.

    The gallery folders are as follows in the Media area.

    Surely this must have been done before?? :-S 

    The issue is getting the ID of the folder chosen when you use mediaCurrent as a parameter on the macro?

    Thanks again for everyones help.

  • kows 81 posts 151 karma points c-trib
    Feb 21, 2011 @ 16:05
    kows
    0

    ive been searching some in projects here and learned some stuff,

    i'm mostly the programmer not the xslt guy.

    maybe this can help:

    http://maanehunden.wordpress.com/2010/07/07/how-to-make-a-xslt-macro-that-can-be-used-inside-an-umbraco-richtext-editor/

     

    edit: this is how i would do it

    http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/list-images-from-mediafolder-in-umbraco-45-plus

     

  • Rob Watkins 369 posts 701 karma points
    Feb 21, 2011 @ 18:15
    Rob Watkins
    0

    Have you added the folder parameter into the actual Macro definition? 

    Go to: Umbraco -> Developer -> Macros -> [Your Macro] :: Parameters

    The parameters are not picked up automatically from the XSLT, and you can't use them until they are added in manually.

  • Rob Watkins 369 posts 701 karma points
    Feb 21, 2011 @ 18:18
    Rob Watkins
    0

    Oh for God's sake, why doesn't the bloody edit work? Sorry, I had a scroll / brain malfunction and missed your last post. Will have a read through.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 21, 2011 @ 19:14
    Kim Andersen
    0

    Hi again Kevin

    Could you try the code I provided, and then change your variable to this:

    <xsl:variable name="folder" select="macro/folder" />

    I can't remember what the mediaCurrent returns, so could you try printing it out in a textarea like this:

    <textarea>
    <xsl:copy-of select="$folder" />
    </textarea>

    /Kim A

  • Kevin Walker 66 posts 87 karma points
    Feb 22, 2011 @ 11:12
    Kevin Walker
    0

    At the risk of tearing my hair out I have now assigned a mediaPicker property to a new Photo Gallery document type that I have created. I choose the medai folder for the photo gallery when I create a page using this new document type.

    I can now see the correct folder id rendered to the browser in a text area as suggested by Kim. It reads 1329.

    I have removed the folder parameter from the XSLT. 

    Happy Days you would think.....however Im still getting the error 'System.OverflowException: Value was either too large or too small for an Int32.' when I try to use the $folder variable instead of a hard coded 1329 in 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"
     exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>
      <xsl:param name="currentPage"/>
      <xsl:template match="/">  
        <xsl:variable name="galleryMediaFolder" select="$currentPage/galleryMediaFolder"/>
        <xsl:variable name="mediaFolderId"><xsl:value-of select="$galleryMediaFolder" /></xsl:variable>
        <textarea>
        <xsl:value-of select="$mediaFolderId"/>
        </textarea>
        <xsl:for-each select="umbraco.library:GetMedia(1329, 1)/Image">
          <li>
            <a class="image" rel="lightbox">
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:GetMedia(@id, 0)/umbracoFile"/>
              </xsl:attribute>
              <img>
                  <xsl:attribute name="src">
                    <xsl:value-of select="umbraco.library:Replace(umbraco.library:GetMedia(@id, 0)/umbracoFile, '.', '_thumb.')"/>            
                  </xsl:attribute>
              </img>        
            </a>
         </li>
      </xsl:for-each>         
      </xsl:template>
    </xsl:stylesheet>

     

    Any further help greatly appreciated before I go the the mental asylum.

    *Rob - On a further point, there have been numerous times including this post on the Our Umbraco forum when I have edited or added a substantial post only for it to be completely lost upon save / submission so I know what you mean, really needs to be sorted out by the Umbraco powers that be!

    Cheers

     

  • kows 81 posts 151 karma points c-trib
    Feb 22, 2011 @ 11:32
    kows
    0

    would be handier if you post your final (error)code. Confuses me :p

    Did you try $mediaFolderId/node/@id ?

  • Rob Watkins 369 posts 701 karma points
    Feb 22, 2011 @ 11:40
    Rob Watkins
    0

    Sorry, just to double check an obvious gotcha - are you getting the overflow exception just when you save the macro, or when you actually use the macro?

  • Kevin Walker 66 posts 87 karma points
    Feb 22, 2011 @ 11:59
    Kevin Walker
    0

    Rob, I didnt even think to check, but it does actually work from the front side when you check the 'Skip Testing' checkbox in the editor when saving the XSLT file. Strange that it will not pass testing in the XSLT parser though.

    I guess we can consider this sorted as a result of everyones contributions (with the exception of the XSLT parser error) as I now have the functionality that I required. I ll mark as solved the one which I feel helped the most which was the suggestion to use a document type with properties as opposed to parameters.

    Many thanks to everyone for their assistance. 

    Cheers

    Kevin

  • Rob Watkins 369 posts 701 karma points
    Feb 22, 2011 @ 12:10
    Rob Watkins
    0

    The reason it doesn't work when you save is that the $currentPage variable is empty, so your document property is empty - all the library functions that expect an ID will return this overflow error on save if you use anything based on the $currentPage (or querystring, or anything that results in an empty string if there is no context). I normally use the Visualize XSLT option and select a node for testing.

    I do like the save to be able to use the testing though and not throw errors, so what I normally do is something like:

    <xsl:variable name="mediaID">
    <xsl:choose>
    <xsl:when test="string($currentPage/galleryMediaFolder) != ''">
    <xsl:value-of select="$currentPage/galleryMediaFolder"/>
    </xsl:when>
    <xsl:otherwise>1</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    Then  just use $mediaID in the library call. Your macro will work propery everywhere there is a currentPage, and will use 1 on save, which although it won't match an actual item, won't throw an exception.

    Kicking myself really, this is such a common issue I could have saved you loads of time, but I misread your original post and thought it was not working in your actual page, sorry!

    I've always used document properties myself - the mediaCurrent macro parameter type is so unintuitive!

Please Sign in or register to post replies

Write your reply to:

Draft