Skip to content

Instantly share code, notes, and snippets.

@tomfulton
Created August 29, 2012 22:30
Show Gist options
  • Save tomfulton/3519737 to your computer and use it in GitHub Desktop.
Save tomfulton/3519737 to your computer and use it in GitHub Desktop.
Widget Dropper XSLT Version
<?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="nodeId" select="/macro/Node" />
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:if test="not(normalize-space($nodeId)) or not($nodeId &gt; 0)">
<xsl:call-template name="errorMessage">
<xsl:with-param name="message" select="'No node selected!'" />
</xsl:call-template>
</xsl:if>
<xsl:variable name="nodeXml" select="umbraco.library:GetXmlNodeById($nodeId)" />
<xsl:if test="$nodeXml/error">
<xsl:call-template name="errorMessage">
<xsl:with-param name="message" select="'The selected node no longer exists!'" />
</xsl:call-template>
</xsl:if>
<xsl:if test="not($nodeXml/self::widget)">
<xsl:call-template name="errorMessage">
<xsl:with-param name="message" select="'The selected node is not a valid Widget node'" />
</xsl:call-template>
</xsl:if>
<xsl:variable name="isBackend" select="contains(umbraco.library:RequestServerVariables('URL'), 'macroResultWrapper')" />
<xsl:choose>
<xsl:when test="$isBackend">
<xsl:apply-templates select="$nodeXml" mode="render-preview" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$nodeXml" mode="render" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="render-preview">
<div class="success" style="background-color:#FFF6BF;border:2px solid #FFD324;border-color:transparent;padding:0 0.8em;">
<h3>
'<xsl:value-of select="./@nodeName" />' Widget will be shown here...
</h3>
</div>
</xsl:template>
<xsl:template match="*" mode="render">
<div class="cms-widget">
<xsl:value-of select="./html" disable-output-escaping="yes" />
</div>
</xsl:template>
<xsl:template name="errorMessage">
<xsl:param name="message" />
<div class="error" style="background-color:#FBE3E4;border:2px solid #FBC2C4;border-color:transparent;padding:0 0.8em;">
<h3>Error rendering Widget:</h3>
<ul>
<li>
<xsl:value-of select="$message"/>
</li>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment