Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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 " "> ]><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 > 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?
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.
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
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
Sorry, It still returns blank. :(
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.
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 " "> ]><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 > 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.
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"/>
forgot to add, that the second textarea would not display, as the "if" condition ("$mediaId > 0") wasn't being hit.
That did the trick - Thanks :)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
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 " "> ]>
<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 > 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?
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...
...then you can call GetMedia with it...
Cheers, Lee.
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
Hi Bjarke,
You'll just need to change the XPath to use the new XML schema, like so:
Cheers, Lee
Hi Lee,
Sorry, It still returns blank. :(
Cheers, Bjarke
Hi Bjarke,
Well, it looks like a little debugging is in order! :-)
Could you try the following and paste back what you find?
Thanks, Lee.
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 " "> ]>
<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 > 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.
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:
Cheers, Lee.
forgot to add, that the second textarea would not display, as the "if" condition ("$mediaId > 0") wasn't being hit.
Hi Lee,
That did the trick - Thanks :)
Cheers, Bjarke.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.