KNOWLEDGE BASE

XSLT Time Saver Functions


Working with Umbraco for as long as we have, we've collated a number of time saving but basic XSLT functions that we find new users often call out for. Here is a selection of some we use on a regular basis that should help you out in your development efforts.

Finding a node by it's ID:

<xsl:variable name="node1" select="$currentPage/ancestor::root//*[@id = 1234]" />
<xsl:variable name="node2" select="umbraco.library:GetXmlNodeById(1234)" />

Using XPath you can trim down the amount of nodes searched by adding anything you know about the location of the node

you're looking for, e.g.:

<!-- Reference to root of site -->
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<!-- I want a NewsItem node that is a direct child node of the News node that is at the root of the site -->
<xsl:variable name="breakingNews" select="$siteRoot/News/NewsItem[@id = 1234]" />

Hopefully this will go some way to helping you with your daily development. Let us know if there is anything specific you need to know.


Need an Umbraco Master?

Here at Simon Antony, we have an in house certified Umbraco Grand Master available for hire. Got a problem with your site, need architecture advice, give us a call to speak to Simon directly and see how we can help

Contact Simon Today!