我正在学习 XPath,在练习使用我在网上找到的示例 xml 文件时,在将 XSL 文件实施到项目中后,应用程序无法呈现任何值。非常感谢任何关于我遗漏或做错的建议。
XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<root>
<Customers>
<Customer>
<Id>1</Id>
<FirstName>Joe</FirstName>
<Surname>Doe</Surname>
</Customer>
</Customers>
<Customers>
<Customer>
<Id>2</Id>
<FirstName>Mary</FirstName>
<Surname>Brown</Surname>
</Customer>
</Customers>
<Customers>
<Customer>
<Id>3</Id>
<FirstName>Paul</FirstName>
<Surname>Smith</Surname>
</Customer>
</Customers>
</root>
XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match ="/">
<root>
<xsl:apply-templates select ="//Customers"/>
</root>
</xsl:template>
<xsl:template match ="//Customer">
<Customer>
<xsl:attribute name="Id">
<xsl:value-of select="Id"/>
</xsl:attribute>
<xsl:attribute name="FirstName">
<xsl:value-of select="FirstName"/>
</xsl:attribute>
<xsl:attribute name="Surname">
<xsl:value-of select="Surname"/>
</xsl:attribute>
</Customer>
</xsl:template>
</xsl:stylesheet>
ASPX:
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/xml/Sample-no-attributes.xml"
TransformFile="~/xml/Sample-no-attributes.xsl"
XPath="/root/Customers">
</asp:XmlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="XmlDataSource1">
<Columns>
<asp:TemplateField HeaderText="CustomerID">
<ItemTemplate>
<%# XPath("Customer/Id")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<%# XPath("Customer/FirstName")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Surname">
<ItemTemplate>
<%# XPath("Customer/Surname")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
请就我在这里做错的事情提供一些帮助。