Copied to clipboard

Flag this post as spam?

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


  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Oct 26, 2010 @ 00:20
    Damiaan
    0

    Get list of images from a folder, error in xslt

    Hi

    I am new to Umbraco an playing with it for almost 36 hours.

    My experience with XSLT is very limited.  I just wanted a list of My images from one of my media folders.

    I found the wiki entry "ListFilesFromMediaFolders" (http://our.umbraco.org/wiki/reference/code-snippets/listfilesfrommediafolderxslt) which was very helpful.  But even when I use this code I can't save the xslt because I get an error about a int32 too small or too large. (see below)

    My code is just plain default stuf from the example. I pasted for your reference at the bottom of this post.  If i start removing the lines one by one it is this line:

      <xsl:variable name="files" select="umbraco.library:GetMedia($mediaFolderID,1)" />

    where i get the error. 

    According to my about page, I use umbraco v 4.5.2 (Assembly version: 1.0.3891.20719).  Which i already understood is the latest you can get at the moment of writing

    Although I tried searching the forums & wiki, I didn't succeeded in finding a solution.I read about very knowledge people on this forum.  I hope you can help.

    Error occured
    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

    <?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"/>
    <!-- This is our Macro Paramater with the alias of mediaFolder -->
    <xsl:param name="mediaFolder" select="/macro/mediaFolder" />

    <!-- The value of mediaFolder is an XML snippet, where we need to select the id attribute from the XML node <node> -->
    <xsl:param name="mediaFolderID" select="$mediaFolder/node/@id" />

    <xsl:template match="/">


    <xsl:if test="$mediaFolderID !=''">
       <!-- Rest of our code will go in here -->
    </xsl:if>

    <!-- if you remove the next line, you won't receive the error -->
    <xsl:variable name="files" select="umbraco.library:GetMedia($mediaFolderID,1)" />
    <!-- Uncomment this for DEBUG and view the HTML source of your page to see the XML snippet -->
    <!--
      <xsl:copy-of select="$files" />
    -->

    <ul id="fileList">
      <!-- For each XML node <node> where the nodeTypeAlias attribute = File -->
      <xsl:for-each select="$files//node [@nodeTypeAlias ='File']">
        <li>
          <!-- On the current XML node <node> find the XML node <data> where the alias atribute = umbracoFile -->
          <!-- This is where the filepath to the file is stored -->
          <a href="{data [@alias='umbracoFile']}">
            <!-- Display the name of the file -->
            <xsl:value-of select="@nodeName"/>
          </a>
        </li>
      </xsl:for-each>
    </ul>

     
    </xsl:template>

    </xsl:stylesheet>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 26, 2010 @ 00:29
    Chriztian Steinmeier
    0

    Hi Damiaan,

    You get the error because Umbraco runs your XSLT on the Content (root) node when saving, to test for fatal errors (XML well-formedness etc.) - there's actually already a fix in the file, but you've circumvented it somehow - the <xsl:if test="$mediaFolderID != '' "> has been closed too early - it's meant to catch this exact scenario.

    So you should put the closing </xsl:if> down between the </ul> and </xsl:template> for an easy fix.

    When that's in place and you're getting errors upon rendering we need to see if you're using the new schema or the old... (the code you have was written for the old XML schema)

    There's a switch available in the web.config for legacy support, though if you're building a new site you'd definitely start with the new schema. Really.

    Let's hear how far you get. 

    /Chriztian 

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Oct 26, 2010 @ 00:53
    Damiaan
    0

    Hi Chriztian

    The error was solved exactly as you predicted.  Thanks a lot!

    I am indeed developing a new site, so activating legacy support sounds ... well you know. 

    Where can should i start to upgrade the xsl to the new schema?

    Kind regards

    ps: At the moment I am not getting any line of code back, but I guess that has to do with me selecting the wrong ID.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 26, 2010 @ 01:28
    Chriztian Steinmeier
    0

    So - on with the new Schema then!

    There's an entry here on the WIKI to get you going: http://our.umbraco.org/wiki/reference/xslt/45-xml-schema

    There's also a couple of tools that can convert most of it for you, but the names/urls escape me right now (you'll learn XSLT better if you do it yourself :-)

    Otherwise - leave a "HELP" comment and you'll get help for sure - umbraco's exactly like that :-)

    /Chriztian

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Oct 26, 2010 @ 12:56
    Damiaan
    0

    Hi Chriztian,

    That's exactly what I was search for.  Thanks again!

    Kind regards

Please Sign in or register to post replies

Write your reply to:

Draft