XSLT Extension - CMS

The CMS library XSLT extension can be used to retrieve useful data about your Umbraco instance. There are many methods available to return XML data from:
  • Data Types
  • Document Types
  • Languages
  • Macros
  • Media Types
  • Members Types
  • Templates

Enabling the XSLT extension for use in your XSLT templates.

Add the following XML snippet to your ~/config/xsltExtensions.config file:

<XsltExtensions>
	...
	<ext assembly="uComponents.Core" type="uComponents.Core.XsltExtensions.Cms" alias="ucomponents.cms" />
	...
</XsltExtensions>

Methods

Here are available methods:

Method Returns Notes
GetDataTypeByGuid(string dataTypeGuid) A node-set of the specified data-type Returns an XPathNodeIterator of the specified data-type by guid.
GetDataTypeById(int dataTypeId) A node-set of the specified data-type Returns an XPathNodeIterator of the specified data-type by Id.
GetDataTypes A node-set of all the data types used within Umbraco. Returns an XPathNodeIterator of all the data types created in Umbraco.
GetDictionaryItem(string key, int languageId) Returns the string value of the dictionary item for the specified language id. Gets the dictionary item for the specified language id.
GetDictionaryItem(string key, int languageId, string defaultValue) Returns the string value of the dictionary item for the specified language id. Gets the dictionary item for the specified language id, with a fall-back default value.
GetDocumentType(int docTypeId, bool includeTabs, bool includePropertyTypes, bool includeAllowedTemplates) A node-set of the specified document-type. Returns an XPathNodeIterator of the specified document-type.
GetDocumentTypes A node-set of all the document types used within Umbraco. Returns an XPathNodeIterator of all the document types created in Umbraco.
GetDocumentTypes(bool includeTabs, bool includePropertyTypes, bool includeAllowedTemplates) A node-set of all the document types used within Umbraco. Returns an XPathNodeIterator of all the document types created in Umbraco.
GetLanguage(int languageId) A node-set of the specified language. Gets the language by id.
GetLanguageByCultureCode(string cultureCode) Returns a node-set of the specified language. Gets the language by culture code.
GetLanguageByNodeId(int nodeId) Returns a node-set of the language by the node id. Gets the language by node id.
GetLanguageIdByNodeId(int nodeId) Returns the id of the language by the node id. Gets the language id by node id.
GetLanguages A node-set of all the languages used within Umbraco Returns an XPathNodeIterator of all the languages created in Umbraco.
GetMacro(string alias) A node-set of the specified macro. Returns an XPathNodeIterator of the specified macro.
GetMacros A node-set of all the macros used within Umbraco. Returns an XPathNodeIterator of all the macros created in Umbraco.
GetMediaType(int mediaTypeId, bool includeTabs, bool includePropertyTypes) A node-set of the specified media-type. Returns an XPathNodeIterator of the specified media-type.
GetMediaTypes A node-set of all the media types used within Umbraco. Returns an XPathNodeIterator of all the media types created in Umbraco.
GetMediaTypes(bool includeTabs, bool includePropertyTypes) A node-set of all the media types used within Umbraco. Returns an XPathNodeIterator of all the media types created in Umbraco.
GetMemberType(int memberTypeId, bool includeTabs, bool includePropertyTypes) A node-set of the specified member-type. Returns an XPathNodeIterator of the specified member-type.
GetMemberTypes A node-set of all the member types used within Umbraco. Returns an XPathNodeIterator of all the member types created in Umbraco.
GetMemberTypes(bool includeTabs, bool includePropertyTypes) A node-set of all the member types used within Umbraco. Returns an XPathNodeIterator of all the member types created in Umbraco.
GetTemplateAlias(int templateId) Returns the alias name of the template. Gets the template alias.
GetTemplateByAlias(int templateId) Returns an XML structure of the template. Gets the template by alias.
GetTemplateById(int templateId) Returns an XML structure of the template. Gets the template by id.
GetTemplateIdByAlias(string templateAlias) Returns the template id. Gets the template id by alias.
GetTemplates Returns an XML structure of all the templates. Gets the templates.
IsLegacyXmlSchema true if (is legacy XML schema); otherwise, false. Checks the Umbraco XML Schema version in use
GetUser(int userId)
GetUserEmail(int userId)
GetUserLanguage(int userId)
GetUserLoginName(int userId)
GetUserName(int userId)
GetUserTypeAlias(int userId)

Usage examples

Here are some example XSLT snippets to show you how.

Data Types

<xsl:template match="/">

	<!-- Gets all data-types definied in Umbraco -->
	<xsl:apply-templates select="ucomponents.cms:GetDataTypes()" />

	<!-- Gets a single data-type from its Id -->
	<xsl:apply-templates select="ucomponents.cms:GetDataTypeById(-87)" />

	<!-- Gets a single data-type from its Guid -->
	<xsl:apply-templates select="ucomponents.cms:GetDataTypeByGuid('5e9b75ae-face-41c8-b47e-5f4b0fd82f83')" />

</xsl:template>

<!-- template to match multiple data-types (from GetDataTypes) -->
<xsl:template match="DataTypes">
	<xsl:apply-templates select="DataType" />
</xsl:template>

<!-- template to match an individual data-type -->
<xsl:template match="DataType">
	<div>
		<p>
			<strong>Name: </strong>
			<xsl:value-of select="@Name" />
		</p>
	</div>
</xsl:template>


Download example XSLT: DataTypes.xslt

Document Types

<xsl:template match="/">

	<!-- Gets all document-types definied in Umbraco -->
	<xsl:apply-templates select="ucomponents.cms:GetDocumentTypes(1, 0, 0)" />

	<!-- Gets a single document-type from its Id -->
	<xsl:apply-templates select="ucomponents.cms:GetDocumentType(1043, 1, 0, 0)" />

</xsl:template>

<!-- template to match multiple document-types (from GetDocumentTypes) -->
<xsl:template match="DocumentTypes">
	<xsl:apply-templates select="DocumentType" />
</xsl:template>

<!-- template to match an individual document-type -->
<xsl:template match="DocumentType">
	<div>
		<p>
			<strong>Name: </strong>
			<xsl:value-of select="@name" />
		</p>

		<p>
			<strong>Alias: </strong>
			<xsl:value-of select="@alias" />
		</p>
	</div>
</xsl:template>


Download example XSLT: DocumentTypes.xslt

Languages

<xsl:template match="/">

	<!-- Gets all languages definied in Umbraco -->
	<xsl:apply-templates select="ucomponents.cms:GetLanguages()" />

	<!-- Gets a single language from its Id -->
	<xsl:apply-templates select="ucomponents.cms:GetLanguage(1)" />

	<!-- Gets a single language from its culture-code -->
	<xsl:apply-templates select="ucomponents.cms:GetLanguageByCultureCode('en-US')" />

</xsl:template>

<!-- template to match multiple languages (from GetLanguages) -->
<xsl:template match="Languages">
	<xsl:apply-templates select="Language" />
</xsl:template>

<!-- template to match an individual language -->
<xsl:template match="Language">
	<div>
		<p>
			<strong>Friendly Name: </strong>
			<xsl:value-of select="@FriendlyName" />
		</p>
		<p>
			<strong>Id: </strong>
			<xsl:value-of select="@Id" />
		</p>
		<p>
			<strong>Culture: </strong>
			<xsl:value-of select="@CultureAlias" />
		</p>
	</div>
</xsl:template>


Download example XSLT: Languages.xslt

Macros

<xsl:template match="/">

	<!-- Gets all the macros defined in Umbraco -->
	<xsl:apply-templates select="ucomponents.cms:GetMacros()" />

	<!-- Gets a single macro from its alias name -->
	<xsl:apply-templates select="ucomponents.cms:GetMacro('Breadcrumbs')" />
		
</xsl:template>

<!-- template to match multiple macros (from GetMacros) -->
<xsl:template match="macros">
	<xsl:apply-templates select="macro" />
</xsl:template>

<!-- template to match an individual macro -->
<xsl:template match="macro">
	<div>
		<p>
			<strong>Name: </strong>
			<xsl:value-of select="name" />
		</p>
		<p>
			<strong>Alias: </strong>
			<xsl:value-of select="alias" />
		</p>
	</div>
</xsl:template>


Download example XSLT: Macros.xslt

Media Types

<xsl:template match="/">

	<!-- Gets all media-types definied in Umbraco -->
	<xsl:apply-templates select="ucomponents.cms:GetMediaTypes(1, 0)" />

	<!-- Gets a single media-type from its Id -->
	<xsl:apply-templates select="ucomponents.cms:GetMediaTypes(1033, 1, 0)" />

</xsl:template>

<!-- template to match multiple media-types (from GetMediaTypes) -->
<xsl:template match="MediaTypes">
	<xsl:apply-templates select="MediaType" />
</xsl:template>

<!-- template to match an individual media-type -->
<xsl:template match="MediaType">
	<div>
		<p>
			<strong>Name: </strong>
			<xsl:value-of select="@name" />
		</p>
		<p>
			<strong>Alias: </strong>
			<xsl:value-of select="@alias" />
		</p>
	</div>
</xsl:template>


Download example XSLT: MediaTypes.xslt

Member Types

<xsl:template match="/">

	<!-- Gets all member-types definied in Umbraco -->
	<xsl:apply-templates select="ucomponents.cms:GetMemberTypes(1, 0)" />

	<!-- Gets a single member-type from its Id -->
	<xsl:apply-templates select="ucomponents.cms:GetMemberTypes(1033, 1, 0)" />

</xsl:template>

<!-- template to match multiple member-types (from GetMemberTypes) -->
<xsl:template match="MemberTypes">
	<xsl:apply-templates select="MemberType" />
</xsl:template>

<!-- template to match an individual member-type -->
<xsl:template match="MemberType">
	<div>
		<p>
			<strong>Name: </strong>
			<xsl:value-of select="@name" />
		</p>
		<p>
			<strong>Alias: </strong>
			<xsl:value-of select="@alias" />
		</p>
	</div>
</xsl:template>


Download example XSLT: MemberTypes.xslt

Templates

<xsl:template match="/">

	<!-- Gets alias name of a template (by Id) -->
	<xsl:value-of select="ucomponents.cms:GetTemplateAlias(1048)" />

</xsl:template>


Download example XSLT: Templates.xslt

Last edited May 3, 2012 at 6:50 PM by leekelleher, version 12