To access media from the media section use the
umbraco.library:GetMedia library function.
In a macro with a mediaCurrent (media picker)
parameter called MediaNode we could use the
following code to access the picked media:
<xsl:variable name="MediaNodeId" select="/macro/MediaNode/node/@id"/>
...
<xsl:if test="$MediaNodeId != '' ">
...
<!-- Show url -->
<xsl:value-of select="umbraco.library:GetMedia($MediaNodeId, 'false')/data [@alias = 'umbracoFile']"/>
...
<!-- Show image -->
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($MediaNodeId, 'false')/data [@alias = 'umbracoFile']"/>
</xsl:attribute>
</img>
...
</xsl:if>
See the Accessing Node Information
hint-page for a more details on media node attributes and
properties.
One important thing to note in when accessing the media library
using GetMedia, the xslt will fail to save without errors due to
validation of the nodeId parameter to GetMedia. To get around this
issue you need to make sure the nodeId is not empty - thus the
<xsl:if test="$MediaNodeId != '' "> check is
added.
Displaying all media under a picked media node (in this example
specified in a MediaPicker type argument $MediaNode on the
macro):
<?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:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="MediaNodeId" select="/macro/MediaNode/node/@id"/>
<xsl:template match="/">
<table>
<xsl:if test="$MediaNodeId != '' ">
<!-- just added as cast-workaround -->
<xsl:for-each select="umbraco.library:GetMedia($MediaNodeId, 'false')/node">
<tr>
<td>
<h5 class="tight">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:if test="@nodeTypeAlias='File'">
<xsl:value-of select="data [@alias = 'umbracoFile']"/>
</xsl:if>
<xsl:if test="@nodeTypeAlias='Image'">
<xsl:value-of select="data [@alias = 'umbracoFile']"/>
</xsl:if>
<xsl:if test="@nodeTypeAlias='Link'">
<xsl:value-of select="data [@alias = 'dokUrl']"/>
</xsl:if>
<xsl:if test="@nodeTypeAlias='Folder'">
?MediaRoot=<xsl:value-of select="@id"/>
</xsl:if>
</xsl:attribute>
<xsl:value-of select="@nodeName"/>
</xsl:element>
</h5>
</td>
<!-- Add other <td> entries here to display further info -->
</tr>
</xsl:for-each>
</xsl:if>
</table>
</xsl:template>
</xsl:stylesheet>