Copied to clipboard

Flag this post as spam?

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


  • Bjarke Petersen 9 posts 29 karma points
    Dec 09, 2010 @ 13:27
    Bjarke Petersen
    0

    Can't figure out how to get url to file

    Hi

    I'm trying to get the url of a mediafile to be used as a link.

    I have tried a lot of the different suggestions, but can't get any of them to work.

     

    What I have:

    The Media:

    The XLST:

    <?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:param name="mediaId"/> 
    <xsl:template match="/">

    <!-- start writing XSLT -->
      <xsl:if test="$mediaId &gt; 0">  
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='mediaId'], 0)/data [@alias = 'umbracoFile']"/>
      </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    The Macro:

    In my masterpage I insert the macro:

    Wich produces this code:

    <umbraco:Macro mediaId="1057" Alias="GetActiveProgram" runat="server"></umbraco:Macro>

    I'm not getting anything back...

    <a href="<umbraco:Macro mediaId='1057' Alias='GetActiveProgram' runat='server' ></umbraco:Macro>" target="_blank">xyz</a>

    Doesn't work either... (also tried to build the "<a href" in the XSLT without luck)

    What am I missing out on?

     

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Dec 09, 2010 @ 14:28
    Lee Kelleher
    0

    Hi Bjarke,

    Which version of Umbraco are you using? (Also could you check the value of the "UseLegacyXmlSchema" setting in the /config/umbracoSettings.config file?)

    Couple of other things you'll need to do:

    Change the <xsl:param name=macroId> to a variable...

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

    ...then you can call GetMedia with it...

    <xsl:value-of select="umbraco.library:GetMedia($mediaId, 0)/data [@alias='umbracoFile']"/>

    Cheers, Lee.

  • Bjarke Petersen 9 posts 29 karma points
    Dec 09, 2010 @ 15:47
    Bjarke Petersen
    0

    Hi Lee,

    Thanks for your reply.

    I'm running version 4.5.2 for .NET 3.5.

    With <UseLegacyXmlSchema>false</UseLegacyXmlSchema>

    I tried the above changes, but I'm still not getting the url (it returns "")

    Looking forward to hear further advice :)

    Cheers, Bjarke

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Dec 09, 2010 @ 15:49
    Lee Kelleher
    0

    Hi Bjarke,

    You'll just need to change the XPath to use the new XML schema, like so:

    <xsl:value-of select="umbraco.library:GetMedia($mediaId, 0)/umbracoFile"/>

    Cheers, Lee

  • Bjarke Petersen 9 posts 29 karma points
    Dec 09, 2010 @ 15:59
    Bjarke Petersen
    0

    Hi Lee,

    Sorry, It still returns blank. :(

     

    Cheers, Bjarke

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Dec 09, 2010 @ 16:06
    Lee Kelleher
    0

    Hi Bjarke,

    Well, it looks like a little debugging is in order! :-)

    Could you try the following and paste back what you find?

    <textarea>
        <xsl:copy-of select="$mediaId" />
    </textarea>
    
    <textarea>
        <xsl:copy-of select="umbraco.library:GetMedia($mediaId, 0)" />
    </textarea>

    Thanks, Lee.

  • Bjarke Petersen 9 posts 29 karma points
    Dec 09, 2010 @ 18:16
    Bjarke Petersen
    0

    Hi Lee,

    Here's the result:

    <textarea>
      <mediaId>
        <File id="1057" version="0e088311-b595-4cc1-be1e-f0347e8f53c2" 
        parentID="1056" level="2" writerID="0" nodeType="1033" template="0" 
        sortOrder="1" createDate="2010-12-09T11:58:55" 
        updateDate="2010-12-09T11:58:55" nodeName="ProgramRef" 
        urlName="programref" writerName="Administrator" 
        nodeTypeAlias="File" path="-1,1056,1057">
        <umbracoFile>/media/153/kinoprogram.pdf</umbracoFile>
        <umbracoExtension>pdf</umbracoExtension>
        <umbracoBytes>3330206</umbracoBytes>
        </File>
      </mediaId>
    </textarea>

    With XSLT:

    <?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="mediaId" select="/macro/mediaId" />
    <xsl:template match="/">
    <textarea>
      <xsl:copy-of select="$mediaId" />
      </textarea>
      
    <!-- start writing XSLT -->
      <xsl:if test="$mediaId &gt; 0">  
            <xsl:value-of select="umbraco.library:GetMedia($mediaId, 0)/umbracoFile"/>
      
       <textarea>
        <xsl:copy-of select="umbraco.library:GetMedia($mediaId, 0)" /> 
      </textarea
        
      </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    I'm only getting 1 textarea?

    Cheers, Bjarke.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Dec 09, 2010 @ 18:18
    Lee Kelleher
    0

    Hi Bjarke,

    Ah yes, the macro is passing through the actual media node (didn't realise it did that when using "mediaCurrent").

    OK, so you just need to do this:

    <xsl:value-of select="$mediaId/File/umbracoFile"/>

    Cheers, Lee.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Dec 09, 2010 @ 18:20
    Lee Kelleher
    0

    forgot to add, that the second textarea would not display, as the "if" condition ("$mediaId &gt; 0") wasn't being hit.

  • Bjarke Petersen 9 posts 29 karma points
    Dec 09, 2010 @ 19:00
    Bjarke Petersen
    0

    Hi Lee,

    That did the trick - Thanks :)

    Cheers, Bjarke.

Please Sign in or register to post replies

Write your reply to:

Draft