我對Xpath很新,雖然它的概念對於長時間的程序員來說很簡單,但我對函數的語法有點困惑......任何幫助表示讚賞。xpath函數語法javascript
讓我們說你有(爲簡單起見,這是從southwind.xml部分)的XML文件
<Orders>
<Order OrderID="10248">
<CustomerID>VINET</CustomerID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T14:25:55</OrderDate>
<RequiredDate>1996-08-01T06:43:44</RequiredDate>
<ShippedDate>1996-07-16T04:00:12</ShippedDate>
<ShipVia>3</ShipVia>
<Freight>32.3800</Freight>
<ShipName>Vins et alcools Chevalier</ShipName>
<ShipAddress>59 rue de l'Abbaye</ShipAddress>
<ShipCity>Reims</ShipCity>
<ShipRegion/>
<ShipPostalCode>51100</ShipPostalCode>
<ShipCountry>France</ShipCountry>
<OrderDetails>
<OrderDetail>
<ProductID>11</ProductID>
<UnitPrice>14.0000</UnitPrice>
<Quantity>12</Quantity>
<Discount>0</Discount>
</OrderDetail>
<OrderDetail>
<ProductID>42</ProductID>
<UnitPrice>9.8000</UnitPrice>
<Quantity>10</Quantity>
<Discount>0</Discount>
</OrderDetail>
<OrderDetail>
<ProductID>72</ProductID>
<UnitPrice>34.8000</UnitPrice>
<Quantity>5</Quantity>
<Discount>0</Discount>
</OrderDetail>
</OrderDetails>
</Order>
<Order OrderID="10249">
<CustomerID>TOMSP</CustomerID>
<EmployeeID>6</EmployeeID>
<OrderDate>1996-07-05T06:39:18</OrderDate>
<RequiredDate>1996-08-16T03:39:38</RequiredDate>
<ShippedDate>1996-07-10T14:39:39</ShippedDate>
<ShipVia>1</ShipVia>
<Freight>11.6100</Freight>
<ShipName>Toms Spezialitäten</ShipName>
<ShipAddress>Luisenstr. 48</ShipAddress>
<ShipCity>Münster</ShipCity>
<ShipRegion/>
<ShipPostalCode>44087</ShipPostalCode>
<ShipCountry>Germany</ShipCountry>
<OrderDetails>
<OrderDetail>
<ProductID>14</ProductID>
<UnitPrice>18.6000</UnitPrice>
<Quantity>9</Quantity>
<Discount>0</Discount>
</OrderDetail>
<OrderDetail>
<ProductID>51</ProductID>
<UnitPrice>42.4000</UnitPrice>
<Quantity>40</Quantity>
<Discount>0</Discount>
</OrderDetail>
</OrderDetails>
</Order>
在Javascript我怎麼構建的路徑(什麼是正確的語法)使用任何xpath函數...我瞭解選擇節點的基礎知識,但是什麼是usting函數的語法..
例如,讓我們說我想SUM的所有訂單數量...這是我得到的地方卡住了,如果我下站在一個函數的語法,其餘的將很容易得到! 什麼會的路徑是我嘗試這樣做,我知道這是非常錯誤..
path="/Orders/Order/OrderDetails/OrderDetail[sum(quantity)]";
預先感謝您
您正在使用哪個XPath庫? – sphair