<?xml version="1.0" encoding="utf-8" standalone ="yes" ?> <books> <book isbn="1"> <title>Beginning XML</title> <author>David Hunter</author> <price>500</price> </book> <book isbn="2"> <title>ASP.NET 3.5 Unleashed</title> <author>Stephen Walther</author> <price>799</price> </book> <book isbn="3"> <title>Programming C#</title> <author>Jesse Liberty</author> <price>450</price> </book> </books>
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output version="1.0" method="xml" indent="yes" /> <xsl:template match="books"> <xsl:element name="books"> <xsl:apply-templates/> </xsl:element> </xsl:template> <xsl:template match="book"> <xsl:element name="book"> <!-- place isbn attribute first --> <xsl:attribute name="isbn"> <xsl:value-of select="@isbn"/> </xsl:attribute> <!-- convert elements to attributes --> <xsl:for-each select="*"> <xsl:attribute name="{name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:for-each > </xsl:element> </xsl:template> </xsl:stylesheet>
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Books</title> </head> <body> <form id="form1" runat="server"> <h2>Books </h2> <asp:gridview ID="Gridview1" runat="server" AutoGenerateColumns="True" DataSourceID="XmlDataSource1"> </asp:gridview> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="books.xml" TransformFile="~/convert.xsl"> </asp:XmlDataSource> </form> </body> </html>