(The textarea will mean the the XML tags are output as plain text so you can see the full XML.) You'll see that the media XML contains more than just the file path - it contains file size, extension and other custom properties you may have defined on the media types*. So the file path is just part of the XML, but it's an important part as it's obviously what's needed to render the path to your media item.
Hope this helps explain a little.
* Sometimes I'll add a text string property on my image media type, called 'altAttribute' so that I can add alt text for images without having to pass that through the macro as a parameter.
The XSLT snippet in your original post seems to be for the old (pre Umbraco 4.5) XML schema. What happened was that Umbraco 4.5 refined the XML structure for the whole Umbraco data-storage, which meant that the XSLT to format data from the XML changed in Umbraco 4.5. Your original snippet would work for the old XML schema, but not for the new schema; so it's basically old XSLT code that doesn't work any more.
Yes, by default all installations from 4.5 will use the new schema. You can set it to use the old one, but I'm not sure why anyone would want to (unless it was to maintain functionality from a very old installation).
My personal approach is to use a media picker on the document type and then pass the value of that media picker through as a numeric parameter in the macro. From that parameter you can use something like this to display the link:
Yeah, that should be fine. All the example above does is bring in a macro property which is the id of your media item, so it doesn't matter where the macro is called from, so long as it contains a property which is the id of the media item. Does that make sense or have I mis-understood?
There's a subtle difference between using a mediaId property and the mediaCurrent macro parameter, which has bit me more than once:
* Using a media picker on a document type you will have to use GetMedia() to get the XML (Dan's code works for this scenario)
* Using mediaCurrent your macro will have the XML already, and you can get it like this:
<xsl:variable name="media" select="/macro/imageLinkMedia"/>
<xsl:template match="/">
<xsl:if test="normalize-space($media)">
<xsl:variable name="mediaNode" select="$media/Image" /><!-- If your media is a custom media type, use its alias here -->
<xsl:if test="$mediaNode/umbracoFile">
<a href="{$mediaNode/umbracoFile}" title="">Download file</a>
</xsl:if>
</xsl:if>
</xsl:template>
Problem by getting the URL of a media item
Hello,
I am trying to get the URL of a macro parameter (mediaCurrent)
I searched for it and found a lot of information but nothing helps.
the <xsl:copy-of select="$imageLinkMedia" /> shows:
media/80122/brochure.pdfpdf181040
But how can i get just the url of the document? I tried by using
<xsl:value-of select="$imageLinkMedia/data[@alias='umbracoFile']"/>
But it does not work.
Thanks
now i tried /macro/imageLinkMedia/*/umbracoFile
and this works
Can somebody explain why? :-)
Hi Dominik,
If you output this:
(The textarea will mean the the XML tags are output as plain text so you can see the full XML.) You'll see that the media XML contains more than just the file path - it contains file size, extension and other custom properties you may have defined on the media types*. So the file path is just part of the XML, but it's an important part as it's obviously what's needed to render the path to your media item.
Hope this helps explain a little.
* Sometimes I'll add a text string property on my image media type, called 'altAttribute' so that I can add alt text for images without having to pass that through the macro as a parameter.
HI Dan,
Thanks,
But i found some solution which mentions I have to use:
/macro/imageLinkMedia/node
/macro/imageLinkMedia/data
/macro/imageLinkMedia/node/@id
All were not working (always empty)
only
/macro/imageLinkMedia/*/umbracoFile
Is working - can you explain why ?
thanks
The XSLT snippet in your original post seems to be for the old (pre Umbraco 4.5) XML schema. What happened was that Umbraco 4.5 refined the XML structure for the whole Umbraco data-storage, which meant that the XSLT to format data from the XML changed in Umbraco 4.5. Your original snippet would work for the old XML schema, but not for the new schema; so it's basically old XSLT code that doesn't work any more.
There are wiki articles about the differences between the old and new schemas and also some examples of the different XSLT used for the different schemas in case you're interested.
Hi Dan,
We are using umbraco 4.7 so the new schema should be included or?
Yes, by default all installations from 4.5 will use the new schema. You can set it to use the old one, but I'm not sure why anyone would want to (unless it was to maintain functionality from a very old installation).
Thanks Dan,
So can you please post how it should be written in the new one?
My personal approach is to use a media picker on the document type and then pass the value of that media picker through as a numeric parameter in the macro. From that parameter you can use something like this to display the link:
Hi Dan,
Property is a macro property and not a document type property because this macro is used on many different document types.
Thanks
Yeah, that should be fine. All the example above does is bring in a macro property which is the id of your media item, so it doesn't matter where the macro is called from, so long as it contains a property which is the id of the media item. Does that make sense or have I mis-understood?
Hi Dan
But <xsl:variablename="mediaId"select="/macro/mediaId"/>
means that macro alias is "mediaId" or?
So let us say my macro alias is "imageLink" and there is a property called "imageLinkMedia" (type= mediaCurrent)
Hi guys,
There's a subtle difference between using a mediaId property and the mediaCurrent macro parameter, which has bit me more than once:
* Using a media picker on a document type you will have to use GetMedia() to get the XML (Dan's code works for this scenario)
* Using mediaCurrent your macro will have the XML already, and you can get it like this:
/Chriztian
HI Chriztian
Thanks for your response.
A few questions to your code. What exactly the "normalize-space" will do?
Media type can either be a image, a pdf, a doc, a xls or something else
THanks a lot
Hi Dominik,
The normalize-space() function just makes sure that an element has a value, by collapsing all whitespace.
If you need to create different output for the edia types, use match templates:
/Chriztian
is working on a reply...