Menu:

Recent Entries

Categories

Archives

Links

Blogs
- Dflying's Night
- David's Untitled Life
- Dflying's Blog in Chinese

This blog is hosted by DreamHost!

Syndicate

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Apply XSLT to XML Using ASP.NET Atlas XSLTView Control

Dflying | 20 April, 2006 05:42

I want to introduce some of the more advanced Atlas Sys.UI.Data controls in this series, including:

  1. Sys.UI.Data.ListView: Display Listible Data Using ASP.NET Atlas ListView Control
  2. Sys.UI.Data.ItemView: Display One Item in a Collection using ASP.NET Atlas ItemView Control
  3. Sys.UI.Data.DataNavigator: Paging Your List Using ASP.NET Atlas PageNavigator Control
  4. Sys.UI.Data.SortBehavior: Sorting Your List Using ASP.NET Atlas SortBehavior
  5. Sys.UI.Data.XSLTView: Apply XSLT to XML Using ASP.NET Atlas XSLTView Control

This is the fifth, also the last post: Apply XSLT to XML Using ASP.NET Atlas XSLTView Control


XSLT is a stylesheet language for XML. It can style your XML raw data as you wish. For more info about the XSLT, please refer to W3C document: http://www.w3.org/TR/xslt.

Atlas provides the XMLDataSource and XSLTView controls to make it possible to retrieve the XML data and XSLT data from server, apply the XSLT to the XML and display to user on the flight. You may use this feature in many ways, such as an online RSS feed reader application.

XSLTView control has following properties:

  1. document: The XML document stores the XML data. You may get the document from an Atlas client side XMLDataSource control and you should always set this property.
  2. transform: The XSLT document stores the XSLT data used for styling your XML. You may also get this by using an XMLDataSource control. You should always set this property.
  3. parameters: The XSLT parameters in XSLT file definitions. Read only.

And following method:

  1. update: Render the XML document using the XSLT. This method is automatically called when the XSLTView got initialized or one of the properties above is changed.

OK, let go though a demo for XSLTView control and XMLDataSource control.

The first step is getting our testing data, both an XML file and an XSLT file. I’ve got these simply by googling and found the files at http://www.w3schools.com/xsl/xsl_client.asp. For this demo, I just choose the raw XML and XSLT files but in the real world, we may easily get the dynamically generated ones from a Web Service or some other CGIs.

Here is the XML. Save it as MyData.xml.

<?xml version="1.0" encoding="iso-8859-1"?>
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
</catalog>

Here is the XSLT. Save it as MyStyle.xsl.

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th align="left">Title</th>
        <th align="left">Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
        <tr>
          <td>
            <xsl:value-of select="title" />
          </td>
          <td>
            <xsl:value-of select="artist" />
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

Let’s define our ASPX page, we have following two parts to add:

  1. Atlas server side control ScriptManager, which is required in every Atlas page to load essential framework files.
  2. <div> with id dataContent, which is used by Atlas to place the rendered content.

<!-- ScriptManager -->
<atlas:ScriptManager runat="server" ID="scriptManager" />
 
<!-- XSLTView here (container) -->
<div id="dataContent">
</div>

The last thing is add Atlas script to the page. There are three sections in the Atlas script block:

Section 1. An XMLDataSource control, used to retrieve the XML data from server.

<xmlDataSource id="dataSource" autoLoad="true" serviceURL="MyData.xml" />

Section 2. Another XMLDataSource control, used to retrieve the XSLT data from server.

<xmlDataSource id="xsltSource" autoLoad="true" serviceURL="MyStyle.xsl" />

Section 3. An XSLTView control used to render the XML using the XSLT definitions. Notice here we are using bindings to set the document and transform properties of the XSLT control.

<xsltView id="dataContent">
    <bindings>
        <binding property="document" dataContext="dataSource" dataPath="document" />
        <binding property="transform" dataContext="xsltSource" dataPath="document" />
    </bindings>
</xsltView>

Run in browser:

Source code for this demo can be downloaded here: http://dflying.dflying.net/1/resources/AtlasXSLTViewDemo.zip.html

Posted in Atlas. Comment: (3). Trackbacks:(202). Permalink
«Next post | Previous post»

Referers

Comments

  1. 1. Rich  |  06/27,2006 at 10:03

    Hey,

    I am having problems binding an xmldatasource to a list view. do you have any suggestions ??? all i either get no data or undefined...

    thanks in advance

  2. 2. ujjabult  |  10/23,2007 at 22:12

    gyqezqnq [URL=http://yowaeyft.com]vuukuvve[/URL] vtcnxkoe http://gpilvdes.com thglqgme llqotlnk

  3. 3. rwzlcaco  |  10/24,2007 at 13:27

    qdhdooaf wuiqmhtx http://cyozleez.com avvqlwhd tzxwfzus [URL=http://dmouufoo.com]ioegbyea[/URL]

Leave a Reply

Auth Image