Copied to clipboard

Flag this post as spam?

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


  • Jonas Persson 12 posts 42 karma points
    Feb 18, 2010 @ 11:57
    Jonas Persson
    0

    Create a "Mediabank, Document Bank"

    I need to create a section on the site where the client can upload documents such as images, pdf, docs whatever.
    Anyone got any good solution for this, or where to start?

    Some kind of preview of the file solution?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 18, 2010 @ 12:11
    Kim Andersen
    0

    Hi Jonas

    Can't the client use the media-section? In there it is possible to upload a lot of different files such as, png, jpg, pdf, flv, doc etc.

    /Kim A

  • dandrayne 1138 posts 2262 karma points
    Feb 18, 2010 @ 12:24
    dandrayne
    1

    Hi Jonas, and welcome to our.

    I'm assuming you want to list the documents on the front-end?  If you just want to upload them, then you can just use the media library..

    If you want a front-end document list, your best bet is to allow editors to upload files to the media library in folders, then allow editors to pick a folder as the basis for the document library.

    The following macro (which I will package up soon, with a few additions), works as follows:

    * In the developer section, Right-click on "xslt" and create new, leaving the "create macro" box checked
    * paste the xslt below into the new xslt file and save
    * Still in the developer section, go up to "macros", expand and find your new macro. 
    * In this screen, select "use in editor"
    * In the "macro parameters" tab, add a new parameter of type "mediaCurrent" and give it an alias of "startNode"
    * Save.  You're now done, and can use the macro from within the wysiwyg

    And in use it goes as follows

    * Editors upload files to the media library within folders (nested folders can be used)
    * When editing a page, they click on "insert macro", choose this one and select a start node in the media library
    * A document list appears

    And more:

    * Each list item in the document list is given a class with the extension of the file, to enable prettifying the doc list
    * If you add a field of alias "fileDescription" to your "file" mediatype, this macro will list the info in the document list
    * If the macro encounters a folder under the start node, it will write out the folder name as a header and create a nested document list
    * The filesize of each item in the library is listed in a readable format (not bytes!)

    <?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:tagsLib="urn:tagsLib"
    exclude-result-prefixes="msxml tagsLib 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:template match="/">

    <xsl:variable name="startNode" select="/macro/startNode/node/@id" />
    <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($startNode, 'true')" />


    <xsl:call-template name="writeList">
    <xsl:with-param name="startNode" select="$mediaFolder" />
    </xsl:call-template>


    </xsl:template>

    <xsl:template name="writeList">
    <xsl:param name="startNode" />
    <ul class="document_list">
    <xsl:for-each select="$startNode/node">

    <xsl:choose>
    <xsl:when test="current()/@nodeTypeAlias='Folder'">
    <li>
    <!-- If this is a folder, call this again -->
    <h4 class="mediaFolder"><xsl:value-of select="current()/@nodeName" /></h4>
    <xsl:call-template name="writeList">
    <xsl:with-param name="startNode" select="current()" />
    </xsl:call-template>
    </li>
    </xsl:when>
    <xsl:otherwise>

    <!--
    When does this expire? If no expiry set, make it expire in the year 2999 (which should be a good year)
    -->
    <xsl:variable name="expiresOn">
    <xsl:choose>
    <xsl:when test="string(string(./data[@alias='docExpireDate'])) != ''">
    <xsl:value-of select="./data[@alias='docExpireDate']" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:text>2999-11-10T00:00:00</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <!--
    if the current file isn't expired, write the list item and file info
    -->
    <xsl:if test="umbraco.library:DateGreaterThanToday($expiresOn)">
    <li>
    <xsl:attribute name="class"><xsl:text>file </xsl:text>
    <xsl:value-of select="current()/data [@alias='umbracoExtension']" />
    </xsl:attribute>
    <h5>
    <a target="_blank" href="{current()/data [@alias='umbracoFile']}">
    <xsl:value-of select="current()/@nodeName" /><xsl:text> </xsl:text>
    (<xsl:call-template name="FileSizeKb">
    <xsl:with-param name="fileSize" select="current()/data [@alias='umbracoBytes']" />
    </xsl:call-template>)
    </a>
    </h5>
    <xsl:if test="string(current()/data [@alias='fileDescription']) != ''">
    <p class="file_description"><xsl:value-of select="current()/data [@alias='fileDescription']" /></p>
    </xsl:if>
    </li>
    </xsl:if>

    </xsl:otherwise>
    </xsl:choose>

    </xsl:for-each>
    </ul>
    </xsl:template>


    <xsl:template name="FileSizeKb">
    <xsl:param name="fileSize" />
    <xsl:if test="string-length($fileSize) &gt; 0">
    <xsl:if test="number($fileSize) &gt; 0">
    <xsl:choose>
    <xsl:when test="round($fileSize div 1024) &lt; 1"><xsl:value-of select="$fileSize" /> Bytes</xsl:when>
    <xsl:when test="round($fileSize div (1024 *1024)) &lt; 1"><xsl:value-of select="round($fileSize div 1024)" />kb</xsl:when>
    <xsl:otherwise><xsl:value-of select="round($fileSize div (1024 * 1024))" />Mb</xsl:otherwise>
    </xsl:choose>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>


    Dan

     

  • Jonas Persson 12 posts 42 karma points
    Feb 18, 2010 @ 15:59
    Jonas Persson
    0

    Thanks for the welcom and the fast replies! :D

    @Kim : I was looking for a more flexible way to manage a mediabank.

    @Dan: I will try it out, sounds promising though :)

    /Jonas

  • Jonas Persson 12 posts 42 karma points
    Feb 18, 2010 @ 16:15
    Jonas Persson
    0

    @Dan : When i copy paste your xslt i get this error?

    /// code ///

    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, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
    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, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
    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)

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 18, 2010 @ 16:19
    Jan Skovgaard
    0

    Hi Jonas

    Try to mark the "skip error testing" and see if it works in the frontend.

    /Jan

  • dandrayne 1138 posts 2262 karma points
    Feb 18, 2010 @ 16:44
    dandrayne
    0

    Yeh, the error can safely be ignored or you could wrap the getMedia with an xsl:if, changing

    <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($startNode, 'true')" />

    to

    <xsl:if test="string($startNode) != ''">
    <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($startNode, 'true')" />
    </xsl:if>

    Dan

  • Jonas Persson 12 posts 42 karma points
    Feb 19, 2010 @ 10:15
    Jonas Persson
    0

    Hi thanks for the replies :)

    Now i get this error:

    "The variable or parameter 'mediaFolder' is either not defined or it is out of scope."

    Tested it with "skip error testing" but it won´t display in the frontend?

    I´m really greatful for your help, kinda new to the xslt parts :)

  • dandrayne 1138 posts 2262 karma points
    Feb 19, 2010 @ 10:36
    dandrayne
    101

    Ooops, perhaps stick the if around the whole start bit, or just revert to the original and skip testing for errors (that's what I do!)

    <xsl:if test="string($startNode) != ''">
    <xsl:variable
    name="startNode" select="/macro/startNode/node/@id" />
    <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($startNode, 'true')" />

                   
    <xsl:call-template name="writeList">
           
    <xsl:with-param name="startNode" select="$mediaFolder" />      
    </xsl:call-template>
    </xsl:if>

    Dan

  • Jonas Persson 12 posts 42 karma points
    Feb 19, 2010 @ 11:02
    Jonas Persson
    0

    Wow :D
    Thank you so much!

    This will be a great package, and I bet alot of people will have good use of it.

    Here´s the final working 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" 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:tagsLib="urn:tagsLib"
    exclude-result-prefixes="msxml tagsLib 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:template match="/">

    <xsl:variable name="startNode" select="/macro/startNode/node/@id" />
    <xsl:if test="string($startNode) != ''">
    <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($startNode, 'true')" />




    <xsl:call-template name="writeList">
    <xsl:with-param name="startNode" select="$mediaFolder" />
    </xsl:call-template>
    </xsl:if>

    </xsl:template>

    <xsl:template name="writeList">
    <xsl:param name="startNode" />
    <ul class="document_list">
    <xsl:for-each select="$startNode/node">

    <xsl:choose>
    <xsl:when test="current()/@nodeTypeAlias='Folder'">
    <li>
    <!-- If this is a folder, call this again -->
    <h4 class="mediaFolder"><xsl:value-of select="current()/@nodeName" /></h4>
    <xsl:call-template name="writeList">
    <xsl:with-param name="startNode" select="current()" />
    </xsl:call-template>
    </li>
    </xsl:when>
    <xsl:otherwise>

    <!--
    When does this expire? If no expiry set, make it expire in the year 2999 (which should be a good year)
    -->
    <xsl:variable name="expiresOn">
    <xsl:choose>
    <xsl:when test="string(string(./data[@alias='docExpireDate'])) != ''">
    <xsl:value-of select="./data[@alias='docExpireDate']" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:text>2999-11-10T00:00:00</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <!--
    if the current file isn't expired, write the list item and file info
    -->
    <xsl:if test="umbraco.library:DateGreaterThanToday($expiresOn)">
    <li>
    <xsl:attribute name="class"><xsl:text>file </xsl:text>
    <xsl:value-of select="current()/data [@alias='umbracoExtension']" />
    </xsl:attribute>
    <h5>
    <a target="_blank" href="{current()/data [@alias='umbracoFile']}">
    <xsl:value-of select="current()/@nodeName" /><xsl:text> </xsl:text>
    (<xsl:call-template name="FileSizeKb">
    <xsl:with-param name="fileSize" select="current()/data [@alias='umbracoBytes']" />
    </xsl:call-template>)
    </a>
    </h5>
    <xsl:if test="string(current()/data [@alias='fileDescription']) != ''">
    <p class="file_description"><xsl:value-of select="current()/data [@alias='fileDescription']" /></p>
    </xsl:if>
    </li>
    </xsl:if>

    </xsl:otherwise>
    </xsl:choose>

    </xsl:for-each>
    </ul>
    </xsl:template>


    <xsl:template name="FileSizeKb">
    <xsl:param name="fileSize" />
    <xsl:if test="string-length($fileSize) &gt; 0">
    <xsl:if test="number($fileSize) &gt; 0">
    <xsl:choose>
    <xsl:when test="round($fileSize div 1024) &lt; 1"><xsl:value-of select="$fileSize" /> Bytes</xsl:when>
    <xsl:when test="round($fileSize div (1024 *1024)) &lt; 1"><xsl:value-of select="round($fileSize div 1024)" />kb</xsl:when>
    <xsl:otherwise><xsl:value-of select="round($fileSize div (1024 * 1024))" />Mb</xsl:otherwise>
    </xsl:choose>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

     

  • Jim C 3 posts 23 karma points
    Nov 17, 2010 @ 20:58
    Jim C
    0

    This was exacly what I was looking for.

     

    Unfortunately I can't get the package working. I'm using the recent version of the XSLT and after following the steps on how to inlclude the macro in the editor, the page is blank.

Please Sign in or register to post replies

Write your reply to:

Draft