XSL Transformations
Now that you know all about creating and manipulating XML it is time to introduce Extensible Stylesheet Language Translations, or XSLT. XSLT is used to transform XML documents into another format altogether. One popular use of XSLT is to transform XML into HTML so that XML documents can be presented visually. The idea is to use an alternate language (XSLT) to transform the XML, rather than rewrite the source code, SQL commands, or some other mechanism used to generate XML.
Conceptually, XSLT is straightforward. A file (an .xsl file) describes the changes (transformations) that will be applied to a particular XML file. Once this is completed, an XSLT processor is provided with the source XML file and the XSLT file, and performs the transformation. The System.Xml.Xsl.XslTransform class is such an XSLT processor. Another processor you will find (introduced in the .NET Framework 2.0) is the XsltCommand object found at SystemXml.Query.XsltCommand. This section looks at using both of these processors.
You can also find some features in Visual Studio that deal with XSLT. The IDE supports items such as XSLT data breakpoints and XSLT debugging. Additionally, XSLT style sheets can be compiled into assemblies even more easily with the command-line style sheet compiler, XSLTC.exe.
The XSLT file is itself an XML document. Dozens of XSLT commands can be used in writing an XSLT file. The first example explores the following XSLT elements (commands):
- stylesheet—This element ...
Get Professional Visual Basic 2012 and .NET 4.5 Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.