Step 1: Create your component

using System.Xml;
using AspXslt.Handling;
using System.Web;

namespace AspXslt.Handling.Samples
    public class HelloWorldComponent : IComponent
        public XmlDocument Execute()
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(@"<?xml version='1.0' encoding='utf-8'?>
<root xmlns=""urn:aspxslt:hellosample"">
  <item description='Hello' />
  <item description='World' />
  <item description='" + HttpContext.Current.Request["name"] + @"' />
            return xml;

Step 2: Create an XSLT file ("test.xslt")

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 

    <xsl:template match="ax:component[@type='AspXslt.Handling.Samples.HelloWorldComponent']">
        <div style="border: solid thin blue">
            <h2>Hello World Component</h2>
                <xsl:for-each select="hel:root/hel:item">
                        <xsl:value-of select="@description"/>

Step 3: Create an XSLT.config file ("test.xslt.config")

<?xml version="1.0" encoding="iso-8859-1" ?>
<document xmlns="urn:aspxslt:handling">
    <component type="AspXslt.Handling.Samples.HelloWorldComponent">
        <!-- Generates an <error> tag if an error of this type occurrs. Otherwise exception is not handled. -->
        <catch type="System.Exception" />

Note: If you use the <xsl:indlude> tag in your xslt file then handler will process the .config files related to the included xslt files first. The same component is not proccessed twice.

Step 4: Configure your web.config to use the XsltHandler

    <add path="*.xsl,*.xslt" verb="*" type="AspXslt.Handling.XsltHandler"/>

Step 5:

Access your xslt file (http://yourhost/yourapp/test.xslt?name=xyz) and see the results.

Last edited Aug 2, 2010 at 2:33 PM by eduardobcastro, version 6


No comments yet.