Applying XSLT to XML Using ASP.NET
(Page 1 of 5 )
This article explains the basics of XSL to transform XML documents using simple examples. We will gradually focus on using ASP.NET to implement XSLT for any XML document and even to database queries. It introduces different ways of implementing XSL from browser’s perspective and server’s perspective. We will also discuss some tips to generate automated XML from database queries and then transform them to HTML using XSL transformations.
Introduction to XSL
Anyone who designs web pages using any tool/designer would certainly know about what CSS is. We use HTML in combination with CSS to design and present web pages in a more efficient manner. Basically a style sheet presents a sheet of styles, which would affect certain tag(s) in a web document. By modifying the underlying style sheets, sometimes the look and feel of entire website gets changed dramatically.
As HTML is made up of standard pre-defined tags, we can simply design and apply style sheets for necessary tags using CSS, and browser can understand all those details very easily. But any XML document is generally designed using user-defined tags (elements) to which browser may not understand all those new tags (elements). Just like we use CSS to present HTML document in a well-formatted and understandable manner, we use XSL to present (transform) an XML document in any format we require.
XSL stands for eXtensible Stylesheet Language. It is a language used to design and apply style sheets especially for XML documents. Originally the research started to provide style sheet technology to XML using XSL, but finally ended up with three more divisions of XSL. So, XSL now consists of three parts namely XSLT, XPath and XSL-FO. XSLT is a language for transforming XML documents (even today, several programmers call XSLT as XSL). XPath is a language to filter, search or sort information available in XML documents. XSL-FO is a language for formatting XML documents. In this article we mainly focus on XSLT, which stands for XSL Transformations.
XSLT can also be used to transform an XML document to another XML document (it need not be only HTML document). Another beauty of XSLT is that it internally works/traverse using XPath language. We can even conclude that “The better we learn about XPath, the better XSLT we can design”. Although this article mainly focuses on XSL, I suggest you to go through the fundamentals of XPath language for a better understanding (but not necessary for this article).
Another important issue is that “not all the browsers can understand XSLT technology”. Specifically old browsers like IE5, IE5.5, Netscape 4 etc, are not compatible with XSL or XSLT files to the full-fledged recommendations of W3C. They were developed on a working draft of W3C, which was not yet completed by the time of their releases. IE6 or above and NN6 or above are completely compatible with standard XSL(T) specifications recommended by W3C. But if we use any server side programming to implement XSLT (like ASP.NET), we can overcome the compatibility issues of any browser (as the transformation takes place at server without browser’s knowledge). This issue is deeply examined in the later part of this article.
Next: A Simple Example on XSLT >>
More XML Articles
More By Jagadish Chaterjee