Index

  1. Configuration
  2. Using Landscape
  3. Examples
    1. Basic usage
    2. Dynamic User Controls
    3. Nesting templates
    4. Template2Template parameters
    5. Widgets
    6. Smart includes
    7. XSLT Extension Reference

Configuration

Landscape's behavior can be configured easily through the Web.Config file.

In order for landscape to work correctly you have to tell the library where to retrieve templates, widgets, and smart includes.

Every source directory must have a @path and a @priority attribute. Landscape looks up templates from sources ordered by their priority, so the source with the highest priority will be the first to be processed.

 

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="landscape" type="Landscape.Configuration" allowLocation="true" allowDefinition="Everywhere"/>
  </configSections>
  <appSettings/>
  <connectionStrings/>
  <landscape>
    <landscapeSettings>
      <!-- wether to enable XSLT template caching -->
      <add key="landscapeXSLTCaching" value="True"/>
      <!-- virtual source directory for dynamic user controls -->
      <add key="landscapeUserControlsVDir" value="~/UserControls"/>
    </landscapeSettings>
    <!-- directories in which to look for templates -->
    <landscapeSources>
      <add path="/Templates" priority="2"/>
      <add path="/InternalTemplates" priority="1"/>
    </landscapeSources>
    <!-- smart includes directories -->
    <landscapeIncludes>
      <add path="/InternalTemplates/Includes" priority="2"/>
      <add path="/Templates/Includes" priority="1"/>
    </landscapeIncludes>
    <!-- widget directories -->
    <landscapeWidgets>
      <add path="/InternalTemplates/Widgets" priority="1"/>
      <add path="/Templates/Widgets" priority="2"/>
    </landscapeWidgets>
    <!-- custom XSLT extensions definition -->
    <landscapeXsltExtensions>
      <add alias="urn:XsltCustomExtension" assembly="LandscapeFramework" type="LandscapeFramework.XsltExtensions.XsltCustomExtension"/>
    </landscapeXsltExtensions>
  </landscape>
</configuration>

 

Using Landscape

Landscape's rendering result can be easily displayed into an .aspx page through a standard ASP.NET placeholder.

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LandscapeFramework._Default" %>
<asp:placeholder id="placeholder1" runat="server"></asp:placeholder>

 

Default.aspx.cs

using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Landscape;

namespace LandscapeFramework
{
    public partial class _Default : System.Web.UI.Page
    {
        protected global::System.Web.UI.WebControls.PlaceHolder placeholder1;

        protected void Page_Load(object sender, EventArgs e)
        {
            Renderer.Render("TemplateFileNameWithoutExtension", new DataSet(), placeholder1);
        }
    }
}

 

Examples

Basic usage

 

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:template match="/">
    <html>
      <head>
        <title>Landscape Presentation Framework - Basic Usage</title>
      </head>

      <body>
        <form id="Form1" method="post" runat="server">
          <div>
            <h1>Landscape Presentation Framework - Basic Usage</h1>
            <p>The quick brown fox jumped over the lazy dog</p>
          </div>
        </form>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

 

Dynamic User Controls

~/Templates/UserControlsTemplate.xslt

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:template match="/">
    <html>
      <head>
        <title>Landscape Presentation Framework - Dynamic User Controls</title>
      </head>

      <body>
        <form id="Form1" method="post" runat="server">
          <div>
            <h1>Landscape Presentation Framework - Dynamic User Controls</h1>
            <br/>
            <lsc:control name="TestUserControl" param1="foo" param2="bar" param3="9999"/>
          </div>
        </form>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet> 

 

~/UserControls/TestUserControl.aspx.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LandscapeFramework.UserControls
{
    public partial class TestUserControl : System.Web.UI.UserControl
    {
        #region Controls declaration
        protected global::System.Web.UI.WebControls.Button TestButton;
        protected global::System.Web.UI.WebControls.Label TestParam1;
        protected global::System.Web.UI.WebControls.Label TestParam2;
        protected global::System.Web.UI.WebControls.Label TestParam3;
        #endregion

        #region Configurable properties declaration
        public string param1 { set; get; }
        public string param2 { set; get; }
        public int param3 { set; get; }
        #endregion

        protected override void OnInit(EventArgs e) {
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            TestParam1.Text = param1;
            TestParam2.Text = param2;
            TestParam3.Text = param3.ToString();
        }

        protected void TestButton_Click(object sender, EventArgs e) {
            Response.Write("TestButton has been clicked");
        }
    }
}

 

~/UserControls/TestUserControl.aspx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="LandscapeFramework.UserControls.TestUserControl" %>
<h4>Test user control</h4>
<p>Value of param1: <asp:Label ID="TestParam1" runat="server"></asp:Label></p>
<p>Value of param2: <asp:Label ID="TestParam2" runat="server"></asp:Label></p>
<p>Value of param3: <asp:Label ID="TestParam3" runat="server"></asp:Label></p>
<asp:Button ID="TestButton" runat="server" Text="Button" OnClick="TestButton_Click" />

 

Nesting templates

~/Templates/NestedTemplate.xslt

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:template match="/" lsc:wrapper="Layouts/NestedTemplateLayout">
    
    <div>
      <h1>Landscape Presentation Framework - Nested templates</h1>
    </div>
    
  </xsl:template>
  
</xsl:stylesheet>

 

~/Templates/Layout/NestedTemplateLayout.xslt

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:template match="/">
    <html>
      <head>
        <title>Landscape Presentation Framework - Nested Templates</title>
      </head>

      <body>
        <form id="Form1" method="post" runat="server">
          <!-- This placeholder will be replaced with the actual content from ~/Templates/NestedTemplate.xslt -->
          <lsc:pholder/>
        </form>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

 

Template2Template params

~/Templates/NestedTemplate.xslt

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:template match="/" lsc:wrapper="Layouts/NestedTemplateLayoutWithParameters">

    <div>
      <h1>Landscape Presentation Framework - Nested templates with parameters</h1>
      <p>It is possible to define xslt parameters used to render the parent template.</p>
      <p>Setting layoutParam1 as 'foo'...</p>
      <lsc:param name="layoutParam1">foo</lsc:param>
      <p>Setting layoutParam2 as 'bar'...</p>
      <lsc:param name="layoutParam2">bar</lsc:param>
      <p>Setting layoutParam3 as html</p>
      <lsc:param name="layoutParam3">
        <h5>Htmlcode</h5>
        <p>This is html code passed by child</p>
      </lsc:param>
    </div>

  </xsl:template>

</xsl:stylesheet>

 

~/Templates/Layout/NestedTemplateLayoutWithParameters.xslt

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:param name="layoutParam1"/>
  <xsl:param name="layoutParam2"/>
  <xsl:param name="layoutParam3"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>Landscape Presentation Framework - Nested Templates with parameters</title>
      </head>

      <body>
        <form id="Form1" method="post" runat="server">
          <lsc:pholder/>
          <h3>Parameters passed by child template</h3>
          <p>layoutParam1: <xsl:value-of select="$layoutParam1"/> </p>
          <p>layoutParam2: <xsl:value-of select="$layoutParam2"/></p>
          <p>
            layoutParam3 (html):<br/> <xsl:value-of select="$layoutParam3" disable-output-escaping="yes"/>
          </p>
        </form>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

 

Widgets

~/Templates/Widgets/ExampleWidget.xslt

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#x00A0;">
<!ENTITY agrave "&#224;">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
xmlns:lsc="http://land.scape"
xmlns:lsc.ext="urn:landscape"
exclude-result-prefixes="xsl asp lsc lsc.ext">

<xsl:param name="param1"/>
<xsl:param name="param2"/>

<xsl:template match="/">
<h3>Example Widget</h3> 
<ul>
<li>Param1: <xsl:value-of select="$param1"/></li>
<li>Param2: <xsl:value-of select="$param2"/></li>
</ul>
</xsl:template>

</xsl:stylesheet>

 

~/Templates/WidgetTemplate.xslt

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:template match="/">
    <html>
      <head>
        <title>Landscape Presentation Framework - Widgets inclusion</title>
      </head>

      <body>
        <form id="Form1" method="post" runat="server">
          <div>
            <h1>Landscape Presentation Framework - Widgets inclusion</h1> 
            <br/>
            <lsc:widget name="ExampleWidget" param1="param1value" param2="param2value"/> 
          </div>
        </form>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

 

Smart includes

 

<?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"
				xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="http://land.scape"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:include href="common.xslt!"/>
  <xsl:include href="common.xslt"/>
  
  <xsl:template match="/">
    <html>
      <head>
        <title>Landscape Presentation Framework - Smart Includes</title>
      </head>

      <body>
        <form id="Form1" method="post" runat="server">
          <div>
            <h1>Landscape Presentation Framework - Smart Includes</h1>
            <p>This page is an example of how you can use global include folders.</p>
            <p>Since Landscape features template folder lookup priority, it could happen that you cannot determine exactly the base URI of a template.</p>
            <p>In this case, using the <b>!</b> suffix while defining the @href attribute for an xsl:include or xsl:import, you can tell the library to lookup for a file in the configured include folders.</p>
            <p>Example: <b>&lt;xsl:include href="common.xslt!"/&gt;</b> will look for common.xslt in the folder defined into Web.Config landscapeIncludes
            &lt;landscapeIncludes/&gt; section, while <b>&lt;xsl:include href="common.xslt"/&gt;</b> in the current folder.</p>
            <br/>
            <xsl:call-template name="templateFromSmartIncludeFolder"/>
            <xsl:call-template name="templateFromBaseFolder"/>
          </div>
        </form>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

 

XSLT Extension Reference

Landscape exposes a basic set of function for use into XSLT templates. These functions can be called through

 

<xsl:value-of select="lsc.ext:FuntionName($foo, $bar, ...)"/>

 

Function name Description
lsc.ext:ToLower(string s) Converts a string to lowercase
lsc.ext:ToUpper(string s) Converts a string to uppercase
lsc.ext:UCFirst(string s) Converts the first char of a string to uppercase
lsc.ext:Split(string s, string separator) Returns an XPATH Navigable object containing splitted values
lsc.ext:AppSetting(string settingName) Retrieves the specific setting identified by settingName and defined in the section of the current Web.config file

Last edited Nov 3, 2011 at 5:09 AM by Kunyo, version 1

Comments

No comments yet.