XSLT Basics

What is XSLT

XSLT, or eXtensible Stylesheet Language Transformations, is a document that is applied programmatically to an XML Document to manipulate the data. The structure of XSLT resembles that of XML, and contains specialized tags to perform specific actions to the data.
In umbraco, XSLT is utilized through the use of macros, which are the dynamic building block of front-end content. These templates can be used for various tasks, including the building of navigation structures, display of content nodes in a customizable format.
umbraco also exposes a series of functions to XSLT documents for the manipulation of the data beyond the standard capabilities of XSLT functions. These XSLT Extensions are easily referenced within the mark-up of the XSLT, allowing for easy manipulation of the data for even the most novice developers.

How umbraco uses XSLT.

Umbraco utilizes XSLT to dynamically render content such as navigational structures, lists, and nearly anything you can dream of. This is accomplished through the use of Macros.

Creating Your First XSLT Macro
Creating an XSLT macro is very easy.
1. Go to the developers section in the administration area.

2. Right click on the XSLT folder, and select create.
3. You will receive a dialog where you can specify the name, select an XSLT template, and specify if you want to automatically create the Macro for this template.

4. Specify the name of the new XSLT file, check Create Macro, and select a template if you desire. Click Create.

5. You have now created the XSLT file and the Macro for rendering the content.

Now that we have the XSLT created, we need to customize it to output our content the way we like.

XSLT - The Basics

The standard XSLT file consists of a few different parts. Understanding these parts will allow you to do much more with XSLT than you probably realize.
First, we have the declaration of the XML file, since XSLT is structured off of XML. This consists of the various entries at the top of the file. Unless you are adding customized functions to your XSLT, this will typically not be edited.



<?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%22

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"/>


Next, we have a parameter declaration that is very important to us as it is the default link to the content published in the site. This parameter contains all the data in the site, but is focused on the current page that is loaded. Thus it is named "currentPage".

<xsl:param name="currentPage"/>

Below this, we have our template. This is the portion that is responsible for the output.



<xsl:template match="/">
</xsl:template>


And finally, we close out the template, since this is XML, everything must be properly structured.

</xsl:stylesheet>


Now that we know what the basic things are here, we can look into what can be done.

0 comments:

:a: :b: :c: :d: :e: :f: :g: :h: :i: :j: :k: :l: :m: :n:

Post a Comment