At vise XML i XSLT
HejJeg har en XML fil og en XSLT fil. Jeg vil bruge en aspx-side med en xml-control til at vise xml data. Det jeg får vist frem er kun min tabeloverskrifter. Jeg vil gerne have at den viser det hele.
XML:
<?xml version="1.0" encoding="utf-8" ?>
<CDLIST>
<XMLTITLE>My CD Collections</XMLTITLE>
<CD>
<TITLE>Spider-Man 3</TITLE>
<ARTIST>Tobey Maguire</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Sony Pictures</COMPANY>
<PRICE>20.90</PRICE>
<YEAR>2007</YEAR>
</CD>
<CD>
<TITLE>The Pink Panther</TITLE>
<ARTIST>Steve Martin</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>MGM Distribution Company</COMPANY>
<PRICE>17.90</PRICE>
<YEAR>2006</YEAR>
</CD>
<CD>
<TITLE>Mission: Impossible III </TITLE>
<ARTIST>Tom Cruise</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Paramount Pictures</COMPANY>
<PRICE>12.90</PRICE>
<YEAR>2006</YEAR>
</CD>
<CD>
<TITLE>Indepence Day</TITLE>
<ARTIST>Will Smith</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia Pictures</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1997</YEAR>
</CD>
</CDLIST>
----------------------------
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h2>
<xsl:value-of select="CDList/XMLTITLE"/>
</h2>
<table width="500" border="1">
<tr>
<td width="125">CD Name</td>
<td width="100">Artist</td>
<td width="75">Country</td>
<td width="75">Company</td>
<td width="75">Price</td>
<td width="50">Year</td>
</tr>
<xsl:for-each select="CDList/CD">
<tr>
<td>
<xsl:value-of select="TITLE" />
</td>
<td>
<xsl:value-of select="ARTIST" />
</td>
<td>
<xsl:value-of select="COUNTRY" />
</td>
<td>
<xsl:value-of select="COMPANY" />
</td>
<td>
<xsl:value-of select="PRICE" />
</td>
<td>
<xsl:value-of select="YEAR" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
-----------------------------
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div></div>
<asp:Xml ID="Xml1" runat="server" DocumentSource="~/CDList.xml" TransformSource="~/ListFormat.xsl"></asp:Xml>
</form>
</body>
</html>
----------------------------