Я нахожусь в процессе изучения 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>
Пожалуйста, помогите мне понять, что я здесь делаю неправильно.
/root/Customers/Customer
и изменили другие XPath наId
,FirstName
и т. д. - person JLRishe   schedule 04.08.2013