Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@greystate
Created March 15, 2011 22:35
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 greystate/871656 to your computer and use it in GitHub Desktop.
Save greystate/871656 to your computer and use it in GitHub Desktop.
An attempt to explain when "/root" will work inside an Umbraco macro
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<!-- Up here, "/*" refers to the <macro> element -->
<xsl:template match="/">
<!-- In here, "/*" still refers to the <macro> element -->
<xsl:for-each select="$currentPage/*[@isDoc]">
<!-- In here, "/*" will get you <root> - yay! -->
</xsl:for-each>
<!-- Oh my, back to <macro> with "/*" here -->
<xsl:apply-templates select="$currentPage/bannerProperty" />
</xsl:template>
<xsl:template match="bannerProperty">
<!-- Again, we will get <root> from "/*" here -->
</xsl:template>
</xsl:stylesheet>
@greystate
Copy link
Author

Umbraco macro transforms are executed on a simple little XML document consisting of a <macro> element with a childnode for every macro parameter that was sent to it (e.g. <myParamName>value</myParamName>).

Umbraco then provides access to the entire website structure through the currentPage XSLT param, which acts as a pointer to the page that's currently being rendered.

@Offroadcode
Copy link

That is a perfect example of context in macros, in fact not just macros but XSLT in general. The for-each is a nice little hack to use for switching context although it does feel a little dirty at time the way I use it :)

Add another beer to the list of those I owe you...

@greystate
Copy link
Author

Thanks Pete - I seriously hope we'll get to pay each other those beers queued up :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment