<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl in msxsl csharp"
	xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:csharp="http://c1.composite.net/sample/csharp"	
	xmlns="http://www.w3.org/1999/xhtml">
 
	<xsl:template match="/">
		<html>
			<head />
			<body>
				<textarea>
					<xsl:copy-of select="csharp:GetLatestPages(5)" />
				</textarea>
			</body>
		</html>
	</xsl:template>

 <msxsl:script implements-prefix="csharp" language="C#">
	<msxsl:assembly name="System.Core"/>
	<msxsl:assembly name="System.Xml.Linq"/>
	<msxsl:assembly name="Composite"/>
	<msxsl:assembly name="Composite.Generated"/>

 	<msxsl:using namespace="System.Collections.Generic"/>
 	<msxsl:using namespace="System.Linq"/>
 	<msxsl:using namespace="System.Xml.Linq"/>
 	<msxsl:using namespace="Composite.Data"/>

 	<![CDATA[
	    public static XPathNodeIterator GetLatestPages(int maxItemsToReturn)
	    {
	        using (DataConnection connection = new DataConnection())
	        {
	            IEnumerable<XElement> pageElements =
	                from dataItem in connection.Get<Composite.Data.Types.IPage>()
	                orderby dataItem.ChangeDate descending

	                select new XElement("Pageinfo",
	                    new XAttribute("Title", dataItem.Title),
	                    new XAttribute("ChangeDate", dataItem.ChangeDate),
	                    new XAttribute("Description", dataItem.Description));

	            XElement result = new XElement("Result",
	                pageElements.Take(maxItemsToReturn));

	            return result.CreateNavigator().Select("/Pageinfo");
	        }
	    }
	]]>
 </msxsl:script>

</xsl:stylesheet>
