Posts

Showing posts from August, 2012

How to create an XSLT template

This is the second post in my flash post series on XSLT. We'll start off with some simple examples and move up to advanced as we get the most important components in place. 1: < -- The most basic thing you should know about is how to create and call a template. 2: A template is a procedure that is executed when a certain criteria is met. 3: That we will come back to. 4: --> 5:   6: < !-- First off is the template. A template is the most basic element in an XSLT sheet. 7: This perticular template targets the XML root node, but gives no output.--> 8:   9: < xsl:template match ="/"> 10: < / xsl:template > 11:   12: < !-- The following template targets any node and attribute, 13: but gives no output.--> 14:   15: < xsl:template match ="@* | node()"> 16: < / xsl:template > 17: 18: < !--Now, for the first two, they are exe

XSLT transformations with .Net

How the transformation works with .Net. Using .Net and C# you can do XSL transformations using XslCompiledTransform(). As input to the XSLT engine we use an XSLT sheet, settings (optional), parameters (optional), an XML source and the output path. Note: Please note that if you need to use XSLT 2.0 or XPath 2.0 you should use a third party XSLT engine. 1: // C# code - using .Net 4.0 2:   3: // We want to enable document() functions and script() inside the XSLT code.  In order to allow this in using .Net we include this in the settings.  This gives us a bit more power as far as .Net XSLT support goes. 4: var settings = new XsltSettings( true , true ); 5:   6: // This is the XSLT engine object 7: var xslTransform = new XslCompiledTransform(); 8:   9: // We load the XSLT and settings to the engine. 10: xslTransform.Load(XSLTSheetPath, settings, new XmlUrlResolver()); 11:   12: // As there is no way of g