This project is read-only.

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"] + @"' />
</root>");
            return xml;
        }
    }
}

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

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:ax="urn:aspxslt:handling" 
                xmlns:hel="urn:aspxslt:hellosample" 
                exclude-result-prefixes="ax">

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

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" />
    </component>
</document>

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

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

Step 5:

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

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

Comments

No comments yet.