9.3. Transforming XML Data into HTML Markup

With XML, if you don't like the existing tags or structure, you can change it into whatever format suits you or your application. An Extensible Stylesheet Language (XSL) transformation pulls data from XML nodes and renders the content according to your instructions. In this example (shown in Figure 9-2), you start with an XML file containing details about Web sites. You render the raw data as attractive HTML on an ASP.NET page.

Figure 9-2. Rendering data with an XSL transformation.

9.3.1. Gathering the source XML data

The raw material for a transformation is XML data. Follow these steps to create the XML file:

  1. Add a new XML file named aspsites.xml to the App_Data folder of your project (FileNew FileXML FileAdd).

  2. Use Listing 9-3 as the complete contents of aspsites.xml.

The source file has a simple hierarchical structure: The root, sites, contains one or more site nodes. Each site has a title, url and description node.

Listing 9-3. Sample Raw Data as XML
<?xml version="1.0" encoding="utf-8" ?> <sites> <site> <title>The Official Microsoft ASP.NET ...

Get ASP.NET 3.5 For Dummies® 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.