<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Frederik Vig - ASP.NET developer &#187; Umbraco</title>
	<atom:link href="http://www.frederikvig.com/category/umbraco/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederikvig.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Dec 2011 23:33:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Starting out with XSLT in Umbraco</title>
		<link>http://www.frederikvig.com/2010/03/starting-out-with-xslt-in-umbraco/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=starting-out-with-xslt-in-umbraco</link>
		<comments>http://www.frederikvig.com/2010/03/starting-out-with-xslt-in-umbraco/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 12:52:54 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[Umbraco]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1121</guid>
		<description><![CDATA[I&#8217;ve just started learning Umbraco, which is a popular open source content management system, originally from Danmark, but now with developers across the world. Umbraco stores much of its data as XML in the database, and recommends using XSLT for transforming it to HTML. You can however use regular ASP.NET code if you wish (or ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just started learning <a href="http://www.umbraco.org">Umbraco</a>, which is a popular open source content management system, originally from Danmark, but now with developers across the world.  Umbraco stores much of its data as XML in the database, and recommends using XSLT for transforming it to HTML. You can however use regular ASP.NET code if you wish (or a mix of both). </p>
<p>I&#8217;m a beginner when it comes  <a href="http://www.w3.org/TR/xslt">XSLT</a> so I browsed through a few tutorials, and read the <a href="http://www.w3.org/TR/xslt">XSLT recommendation</a> by <a href="http://www.w3.org/">W3C</a> (along with the <a href="http://www.w3.org/TR/xpath/">XPath</a> and <a href="http://www.w3.org/TR/xquery/">XQuery</a> recommendations), and the <a href="http://our.umbraco.org/wiki/reference/xslt">Umbraco XSLT reference</a>, to learn the syntax.</p>
<h3>Umbraco XSLT snippets</h3>
<p>After I was at the point where I could read XSLT (at least the simple ones), and understand it. I created a new blank Umbraco site locally, logged into the administration interface and the developer section. </p>
<p><img src="http://www.frederikvig.com/wp-content/uploads/umbraco-xslt/developer-xslt-section.png" alt="developer section in Umbraco" /></p>
<p>Here you can create new XSLT files that you can use in your Umbraco Macros. The cool thing is that Umbraco comes with a few XSLT snippets for the most used tasks.</p>
<ul>
<li>Clean</li>
<li>Breadcrumb</li>
<li>List Sub Pages As Thumbnails</li>
<li>List Sub Pages By Date And Limit</li>
<li>List Sub Pages By Document Type</li>
<li>List Sub Pages By Level</li>
<li>List Sub Pages From A Changable Source</li>
<li>List Sub Pages From Current Page</li>
<li>List Thumbnails From Current Page</li>
<li>List Whole Structure From Current Page</li>
<li>Navigation Prototype</li>
<li>Related Links</li>
<li>RSS Feed</li>
<li>Sitemap</li>
<li>Table Prototype</li>
</ul>
<p>These are actually just .xslt files that live in the &lt;site root folder&gt;/umbraco/xslt/templates folder. Here you can modify or add more XSLT snippets if you like. This is also useful if you like to open them in <a href="http://www.altova.com/xml-editor/">XMLSpy</a> or <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio</a> for intellisense and syntax highlighting.</p>
<p><img src="http://www.frederikvig.com/wp-content/uploads/umbraco-xslt/xslt-snippet.png" alt="Custom XSLT snippet in Umbraco" /></p>
<h3>Testing XSLT in Umbraco</h3>
<p>Umbraco also gives you the ability to easily test your XSLT. When you open up a XSLT file in Umbraco, you have the &#8220;Visualize XSLT&#8221; button at the top. Select the XSLT you wish to test, and click &#8220;Visualize XSLT&#8221;.</p>
<p><img src="http://www.frederikvig.com/wp-content/uploads/umbraco-xslt/visualize-xslt.png" alt="Visualize XSLT in Umbraco button" /></p>
<p>This will open up a dialog where you can choose content pages that you can use to test with.</p>
<p><img src="http://www.frederikvig.com/wp-content/uploads/umbraco-xslt/visualize-xslt-dialog.png" alt="Visualize XSLT in Umbraco dialog" /></p>
<h3>XML stored in Umbraco database</h3>
<p>Umbraco stores much of its content as XML, if we take a look at the table cmsContentXml in an Umbraco database, you can see how the XML is structured.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;node</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1048&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;b4a59e09-6b0e-49fb-93ce-31282bca9cbf&quot;</span> <span style="color: #000066;">parentID</span>=<span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #000066;">level</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">writerID</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">creatorID</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">nodeType</span>=<span style="color: #ff0000;">&quot;1045&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;1042&quot;</span> <span style="color: #000066;">sortOrder</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">createDate</span>=<span style="color: #ff0000;">&quot;2008-05-02T09:52:36&quot;</span> <span style="color: #000066;">updateDate</span>=<span style="color: #ff0000;">&quot;2010-03-18T21:21:38&quot;</span> <span style="color: #000066;">nodeName</span>=<span style="color: #ff0000;">&quot;Runway Homepage&quot;</span> <span style="color: #000066;">urlName</span>=<span style="color: #ff0000;">&quot;runway-homepage&quot;</span> <span style="color: #000066;">writerName</span>=<span style="color: #ff0000;">&quot;Administrator&quot;</span> <span style="color: #000066;">creatorName</span>=<span style="color: #ff0000;">&quot;Administrator&quot;</span> <span style="color: #000066;">nodeTypeAlias</span>=<span style="color: #ff0000;">&quot;RunwayHomepage&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;-1,1048&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;data</span> <span style="color: #000066;">alias</span>=<span style="color: #ff0000;">&quot;bodyText&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[&lt;p&gt;Runway gives you a bare-bones website that introduces you to a set of well-defined conventions for building an umbraco website.&lt;/p&gt; &lt;p&gt;The Runway website is very simple in form and provided without any design or functionality. By installing Runway, you&amp;rsquo;ll begin with a minimal site built on best practices. You&amp;rsquo;ll also enjoy the benefits of speaking the same &amp;ldquo;language&amp;rdquo; as the rest of the umbraco community by using common properties and naming conventions.&lt;/p&gt; &lt;p&gt;Now that you know what Runway is, it is time to get started using Runway.&lt;/p&gt;]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;data</span> <span style="color: #000066;">alias</span>=<span style="color: #ff0000;">&quot;siteName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Runway<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;data</span> <span style="color: #000066;">alias</span>=<span style="color: #ff0000;">&quot;siteDescription&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[Off to a great start]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/node<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>If we use the &#8220;Insert xslt:value-of&#8221; wizard to insert a new &lt;xsl:value-of&gt; element, we see that the XML elements and attributes from the database get populated in the &#8220;prevalues&#8221; select box for us. </p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/umbraco-xslt/insert-value-wizard.png" alt="Insert xslt:value-of wizard" />
</p>
<p>New properties we add the our document types will automatically get added here as well.</p>
<h3>Good to know</h3>
<p>When going through the various XSLT snippets that Umbraco provides, you&#8217;ll notice a lot of the same code, some is from the built in functionality that Umbraco offers, others are more conventions that the Umbraco community use. The umbracoNaviHide property is a good example of such a convention.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre>
</div>
</div>
<p>umbracoNaviHide is a boolean property that the editor can use to hide a page from navigation. That is what this part checks for.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;">[string(data [@alias='umbracoNaviHide']) != '1']</pre>
</div>
</div>
<p>Since umbracoNaviHide is a boolean property, 1 is true and 0 is false. Notice the syntax for the none built in properties.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;">data [@alias='umbracoNaviHide'])</pre>
</div>
</div>
<p>The xml in the database looks like this.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;data</span> <span style="color: #000066;">alias</span>=<span style="color: #ff0000;">&quot;umbracoNaviHide&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>There are more properties that are good to know about. For an up-to-date list see <a href="http://our.umbraco.org/wiki/reference/umbraco-best-practices">Umbraco&#8217;s wiki</a>.</p>
<h3>Other resources</h3>
<ul>
<li><a href="http://our.umbraco.org/wiki/reference/xslt">Umbraco XSLT reference</a></li>
<li><a href="http://www.w3.org/TR/xslt">XSL Transformations (XSLT) W3C recommendation</a></li>
<li><a href="http://www.w3.org/TR/xpath/">XML Path Language (XPath) W3C recommendation</a></li>
<li><a href="http://www.w3.org/TR/xquery/">XQuery 1.0: An XML Query Language W3C recommendation</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/02/visual-studio-2010-episerver-snippets/" rel="bookmark" title="February 11, 2010">Visual Studio 2010 EPiServer Snippets</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-property/" rel="bookmark" title="July 5, 2009">EPiServer web controls: Property</a></li>
<li><a href="http://www.frederikvig.com/2010/04/listcontrol-appenddatabounditems-and-databind/" rel="bookmark" title="April 19, 2010">ListControl AppendDataBoundItems and DataBind</a></li>
<li><a href="http://www.frederikvig.com/2009/05/episerver-filter-part-1/" rel="bookmark" title="May 28, 2009">EPiServer filter &#8211; part 1</a></li>
<li><a href="http://www.frederikvig.com/2011/02/links-for-episerver-developers-1/" rel="bookmark" title="February 9, 2011">Links for EPiServer Developers &#8211; #1</a></li>
</ul>
<p><!-- Similar Posts took 9.927 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/03/starting-out-with-xslt-in-umbraco/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
