You have an XML file containing layout data that you want transformed into HTML by your XSLT transform at runtime.
Yes, the .NET framework facilitates this. Here is a snipped from
the sitemap on my web site that is transformed at run-time. Instead of having a manually maintained
sitemap.xml
for search engines.
My XML:
<site xmlns="http://redcell.ca/schema/sitemap.xsd" baseurl="http://two-red-cells.com/">
<page id="services" type="category">
<page id="3d modelling" type="content" />
<page id="archiving" type="content" />
<page id="ipad" type="content" />
<page id="proofreading" type="content" />
<page id="web" type="content" />
<page id="writing" type="content" />
</page>
<page id="solutions" type="category">
<page id="barcoding" type="content" />
<page id="crowdsourcing" type="content" />
<page id="intelligent forms" type="content" />
<page id="nui" type="content" />
<page id="rfid" type="content" />
<page id="rtls" type="content" />
<page id="social mining" type="content" />
<page id="telemetry" type="content" />
</page>
<page id="information" type="category">
<page id="sitemap" type="content" />
<page id="contact" type="content" />
<page id="articles" type="content" />
<page id="mobile" type="link" />
<page id="news" type="content" />
<page id="surplus" type="content" />
<page id="twitter" type="link" />
</page>
</site>
My XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:s="http://redcell.ca/schema/sitemap.xsd">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc><xsl:value-of select="s:site/@baseUrl" /></loc>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<xsl:for-each select="//s:page[@type='category']">
<url>
<loc><xsl:value-of select="/s:site/@baseUrl" /><xsl:value-of select="@id" />/</loc>
<changefreq>daily</changefreq>
<priority>0.75</priority>
</url>
</xsl:for-each>
<xsl:for-each select="//s:page[@type='content']">
<url>
<loc><xsl:value-of select="/s:site/@baseUrl" /><xsl:value-of select="parent::s:page/@id" />/<xsl:value-of select="@id" /></loc>
<changefreq>daily</changefreq>
<priority>0.50</priority>
</url>
</xsl:for-each>
</urlset>
<xsl:apply-templates select="@* | node()" />
</xsl:template>
</xsl:stylesheet>
The transformation code:
using System;
using System.IO;
using System.Web.UI;
using System.Xml.Xsl;
public partial class sitemap : Page
{
private string _language;
private const string Stylesheet = "sitemap.xml.xslt";
protected override void Render(HtmlTextWriter writer)
{
var xslt = new XslCompiledTransform();
var path = Path.Combine(Globals.SitePath, @"sitemaps\" + Stylesheet);
xslt.Load(path);
var args = new XsltArgumentList();
var filename = "sitemap." + _language + ".xml";
path = Path.Combine(Globals.SitePath, @"sitemaps\" + filename);
xslt.Transform(path, args, writer);
}
}