Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Created February 23, 2011 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leekelleher/840304 to your computer and use it in GitHub Desktop.
Save leekelleher/840304 to your computer and use it in GitHub Desktop.
Generic XSLT template for Media items in Umbraco
<?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"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes" />
<!-- ERROR -->
<xsl:template match="error" mode="media" priority="1">
<xsl:comment>
<xsl:value-of select="." />
</xsl:comment>
</xsl:template>
<!-- IMAGE -->
<xsl:template match="Image" mode="media" priority="1">
<xsl:if test="normalize-space(umbracoFile)">
<img src="{umbracoFile}" height="{umbracoHeight}" width="{umbracoWidth}" alt="{(altText | @nodeName[not(normalize-space(../altText))])[1]}" />
</xsl:if>
</xsl:template>
<!-- FOLDER -->
<xsl:template match="Folder" mode="media" priority="1">
<xsl:if test="*[@nodeName]">
<ul title="{@nodeName}">
<xsl:for-each select="*[@nodeName]">
<li>
<xsl:apply-templates select="." mode="media">
<xsl:sort select="@sortOrder" order="ascending" data-type="number" />
</xsl:apply-templates>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
<!-- FILE -->
<xsl:template match="File" mode="media" priority="1">
<xsl:if test="normalize-space(umbracoFile)">
<a href="{umbracoFile}">
<xsl:value-of select="@nodeName" />
<!-- possible to use "umbracoExtension" and "umbracoBytes" here -->
</a>
</xsl:if>
</xsl:template>
<xsl:template match="*[@id]" mode="media" priority="0" />
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment