<?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:rssdatehelper="urn:rssdatehelper"><channel><title>Kasper B </title><link>http://www.kasperb.dk</link><pubDate></pubDate><generator>umbraco</generator><description>no intellisense</description><language>en</language><item><title>Circumventing the macro placeholder</title><link>http://www.kasperb.dk/2009/5/27/circumventing-the-macro-placeholder.aspx</link><pubDate>Wed, 27 May 2009 12:00:51 GMT</pubDate><guid>http://www.kasperb.dk/2009/5/27/circumventing-the-macro-placeholder.aspx</guid><content:encoded><![CDATA[ 
<p>The topic of the previous post was inline xsl in umbraco
master&nbsp;templates.</p>

<p>Another way to circumvent the macro&nbsp;placeholder for those
transformations that are only used in templates (main navigations
and stuff) - is to create a component that allows you the input
the&nbsp;path of a xsl file - load it up and do the
transformation.</p>

<p>Candidates for this is xsl files wrapped in macros that do not
have a tick in the "Use in editor" field - the gain should be a
"simpler" umbraco installation - and a more transparent development
process - and no more need to look in the macro section with the
sole purpose to find out which xsl file it has a reference to
:).</p>

<p>Prototype code that does the job is done in 67 lines - including
debug code, import and namespace declarations.</p>

<pre>
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Text;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Xml;<br />
using System.Xml.Xsl;<br />
using System.IO;<br />
<br />
<br />
namespace InlineXsl<br />
{<br />
    [ToolboxData("&lt;{0}:XslFile runat=server&gt;&lt;/{0}:XslFile&gt;")]<br />
    public class XslFile : Literal<br />
    {<br />
        private string _xslpath = "";<br />
        public string XslPath {<br />
            get { return _xslpath; }<br />
            set { _xslpath = value; }<br />
        }<br />
        private bool _debugmode = false;<br />
        public bool DebugMode<br />
        {<br />
            get { return _debugmode; }<br />
            set { _debugmode = true; }<br />
        }<br />
        protected override void Render(HtmlTextWriter writer)<br />
        {<br />
            try<br />
            {<br />
                XmlDocument xd = new XmlDocument();<br />
                xd.Load(HttpContext.Current.Server.MapPath(XslPath));<br />
                XslCompiledTransform xslt = new XslCompiledTransform();<br />
                xslt.Load(xd);<br />
                XsltArgumentList xslArg = umbraco.macro.AddMacroXsltExtensions();<br />
                xslArg.AddExtensionObject("urn:umbraco.library", new umbraco.library());<br />
                xslArg.AddParam("currentPage", "", umbraco.library.GetXmlNodeCurrent().Current);<br />
                xslt.Transform(umbraco.library.GetXmlAll().Current, xslArg, writer);<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                if (DebugMode)<br />
                {<br />
                    writer.Write("&lt;div style='color:red;border:1px solid red;padding:10px;'&gt;Error in xsl: &lt;br /&gt;&lt;pre&gt;" + ex.ToString() + "&lt;/pre&gt;&lt;/div&gt;");<br />
                }<br />
                else<br />
                {<br />
                    try<br />
                    {<br />
                        HttpContext.Current.Trace.Warn("Error in inline xsl", ex.ToString());<br />
                    }<br />
                    catch { }<br />
                }<br />
            }<br />
        }<br />
    }<br />
}
</pre>

<p>When using it in templates it looks like this:</p>

<pre>
  &lt;Inline:XslFile XslPath="/xslt/test.xslt" runat="server" /&gt;
</pre>

<p>Is it something worth adding to the Umbraco project?</p>
]]></content:encoded></item><item><title>Xsl transformations in templates for umbraco v4</title><link>http://www.kasperb.dk/2009/3/10/xsl-transformations-in-templates-for-umbraco-v4.aspx</link><pubDate>Tue, 10 Mar 2009 20:43:19 GMT</pubDate><guid>http://www.kasperb.dk/2009/3/10/xsl-transformations-in-templates-for-umbraco-v4.aspx</guid><content:encoded><![CDATA[ 
<p>This weekend&nbsp;I finally got around to play with umbraco v4,
and its a joy!</p>

<p>I really like the new .net masterpage templates, and will try to
share how I experienced some of the nice new features that they
provide.</p>

<p>First of, its now possible to use&nbsp;.net code&nbsp;in the
templates, which certainly will raise the numbers of wtf's per
minute - a quick example:</p>

<p>You can now use something like&nbsp;this directly in your
template</p>

<pre>
 &lt;asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"&gt;<br />
&lt;% if (Request.QueryString["test"] != null) { %&gt;<br />
Now theres a test in the querystring<br />
&lt;% } else { %&gt;<br />
Add a &lt;a href="?test=haha"&gt;test in the querystring&lt;/a&gt;<br />
&lt;% }%&gt;<br />
&lt;/asp:Content&gt;
</pre>

<p><br />
Aswell as inserting standard .net controls and binding them&nbsp;to
datasources</p>

<pre>
&lt;script language="c#" runat="server"&gt;<br />
protected void Page_Load() {<br />
 System.Collections.Generic.List&lt;string&gt; list = new System.Collections.Generic.List&lt;string&gt;();<br />
 list.Add("Boom");<br />
 rpt.DataSource = list;<br />
 rpt.DataBind();<br />
}<br />
&lt;/script&gt;
<br />
<br />
&lt;asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"&gt;<br />
 &lt;asp:Repeater id="rpt" runat="server"&gt;<br />
 &lt;ItemTemplate&gt;<br />
  &lt;%# Container.DataItem %&gt;<br />
 &lt;/ItemTemplate&gt;<br />
 &lt;/asp:repeater&gt;<br />
&lt;/asp:Content&gt;
</pre>

<p>Now that this is a fact, why not try to do something useful</p>

<p>How to use inline xsl in umbraco templates:</p>

<p>1: Create&nbsp;a custom control that takes the literal contents
(which is the text/code in between the start and end element of the
custom control) assumes that its xsl and then perform the
transformation in the overridden render method.</p>

<p>2: In order to make it work as the xsl based macros - add in the
umbraco xml data, the currentPage param and the xsl extension
objects.</p>

<p>I have done so and the result is baffling - it works!</p>

<p>&nbsp;Its now&nbsp;possible to do something like:</p>

<pre>
&lt;%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %&gt;<br />
&lt;%@ Register assembly="InlineXsl" namespace="InlineXsl" tagprefix="Inline" %&gt;
&lt;asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"&gt;<br />
 &lt;Inline:XslTransformer ID="mytransform" runat="server"&gt;<br />
 &lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
 &lt;!DOCTYPE xsl:stylesheet [ &lt;!ENTITY nbsp "&amp;#x00A0;"&gt; ]&gt;<br />
 &lt;xsl:stylesheet<br />
  version="1.0"<br />
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />
  xmlns:msxml="urn:schemas-microsoft-com:xslt"<br />
  xmlns:umbraco.library="urn:umbraco.library"<br />
  exclude-result-prefixes="msxml umbraco.library"&gt;<br />
  &lt;xsl:output method="html" omit-xml-declaration="yes"/&gt;
  &lt;xsl:param name="currentPage"/&gt;<br />
  &lt;xsl:template match="/"&gt;<br />
   You are on the page &lt;xsl:value-of select="$currentPage/@nodeName" /&gt;<br />
  &lt;/xsl:template&gt;<br />
 &lt;/xsl:stylesheet&gt;
 &lt;/Inline:XslTransformer&gt;<br />
&lt;/asp:Content&gt;
</pre>

<p>Which is pure inline xsl in your templates :)</p>

<p>To make it a bit easier to start up&nbsp;- I added an option to
omit the doctype and stylesheet declarations - which makes it alot
shorter and readable - you just need to add the following attribute
to the custom
control:&nbsp;&nbsp;OmitStyleSheetAndDoctypeDeclaration="True"</p>

<p>Same example:</p>

<pre>
&lt;%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %&gt;<br />
&lt;%@ Register assembly="InlineXsl" namespace="InlineXsl" tagprefix="Inline" %&gt;
&lt;asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"&gt;<br />
    &lt;Inline:XslTransformer ID="mytransform" runat="server" OmitStyleSheetAndDoctypeDeclaration="True"&gt;<br />
  &lt;xsl:param name="currentPage"/&gt;<br />
  &lt;xsl:template match="/"&gt;<br />
   You are on the page &lt;xsl:value-of select="$currentPage/@nodeName" /&gt;<br />
  &lt;/xsl:template&gt;<br />
    &lt;/Inline:XslTransformer&gt;<br />
&lt;/asp:Content&gt;
</pre>

<p>&nbsp;</p>

<p>It really is that easy - try it out for yourself: <a
href="/inlinexsl.zip">download a .zip file with
the assembly containing the custom control</a>, extract - drop it
in&nbsp;your umbraco v4 installations bin folder&nbsp;and copy
paste the code from this page into a master template :)</p>

<p>If it fails you can add the attribute DebugMode="True" aswell -
it will output a nice error message, if you dont - its in the
trace.</p>
]]></content:encoded></item><item><title>Taking it for a testrun</title><link>http://www.kasperb.dk/2009/3/10/taking-it-for-a-testrun.aspx</link><pubDate>Tue, 10 Mar 2009 20:31:21 GMT</pubDate><guid>http://www.kasperb.dk/2009/3/10/taking-it-for-a-testrun.aspx</guid><content:encoded><![CDATA[ 
<p>Ya it seems that Umbraco v4 blog package works!</p>
]]></content:encoded></item></channel></rss>
