Writing templates

This is a good example of a standalone template. It output a simple html page  wih must conform to an XML document.

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:asp="http://schemas.microsoft.com/AspNet/WebControls"
        xmlns:lsc="urn:landscape-xsl"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">
        
  <xsl:param name="wrapperShowRightColumn"/>
  <xsl:param name="wrapperBoxContent"/>        

  <xsl:template match="/">
    <html>
      <body>
        <form id="Form1" method="post" runat="server">
          <lsc:pholder/>
          
          <xsl:if test="$wrapperShowRightColumn = 'true'">
            <div id="rightColumn">
              <h3>Title</h3>
              <p>Lorem ipsum dolor sit amet, et cetera.</p>
            </div>
          </xsl:if>
          <div class="box">
            <xsl:copy-of name="$wrapperBoxContent"/>           
          </div>
        </form>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

You may have noticed the <lsc:pholder/> tag into the form. That can be replaced automatically with some content.

The wrapper accepts two parameters, but let's ignore this for now. Save the template into Wrappers/OuterWrapper.xslt and now you can create the inner template.

<?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="urn:landscape-xsl"
        xmlns:lsc.ext="urn:landscape"
        exclude-result-prefixes="xsl asp lsc lsc.ext">

  <xsl:template match="/" lsc:wrapper="Wrappers/OuterWrapper">
    <h1>Hello, world</h1>
    <p>You have just created a very basic flexible xslt template</p>
    
    <lsc:param name="wrapperShowRightColumn" value="true"/>
    <lsc:param name="wrapperBoxContent">
      <h1>Register Now</h1>
      <p>Blah blah</p>
    </lsc:param>
  </xsl:template>
  
</xsl:stylesheet>

When we define the lsc:wrapper attribute to the main template, we are basically saying that this template has to be enclosed into Wrappers/OuterWrapper. Since there are two extensions for XSLT files around, to improve flexibility the wrapper template must be specified without extension.

The two <lsc:param/> define parameters that will be passed to the wrapper when it will be rendered. You can pass HTML code too.

Using ASP.NET WebControls in a Landscape template

Assuming you have configured some valid sources for user controls, you can create Dynamic User Controls into XSLT templates using a regular XML syntax:

<lsc:control name="Mybutton" buttonLabel="Please, click me"/> 

The name attribute is the file name without extension of the .ascx control residing in the configured source folder.

The other attributes bind directly to the public writable properties of the control.

Using Global Include Folders

To include a file located into the global include folders, just call it with an exclamation mark (!) at the end of the filename

<!-- this is a traditional inclusion -->
<xsl:include href="common.xslt"/>
<xsl:import href="common.xslt"/>

<!-- this is an inclusion from the global folders --> <xsl:include href="common.xslt!"/> <xsl:import href="common.xslt!"/>

 

When the template gets compiled for the first time, these paths are automatically resolved to the real physical path of the file and saved into memory to boost performance.

Using Widgets

To call a widget into a template, just use the same syntax of the user control:

<lsc:widget name="ExampleWidget" param1="param1value" param2="param2value"/>
    <lsc:control name="Mybutton" buttonLabel="Please, click me"/>

Last edited Nov 3, 2011 at 5:47 AM by Kunyo, version 6

Comments

No comments yet.