2012-08-15 64 views
2

鑑於這種記錄結構,這將是我正確的XPath表達式簡單的XPath問題

基地/產品/產品

  1. 選擇與類別=「威特」
  2. 只產品記錄只選擇產品記錄與非空領域的品牌

<product> 
     <productID>?7804407001751?</productID> 
     <name>?Name value?</name> 
     <price currency="EUR">?11.?24?</price> 
     -<productURL> 
      product url value 
     </productURL> 
     -<imageURL> 
      product img url value? 
     </imageURL> 
     -<description> 
      description value 
     </description> 
     -<categories> 
      <category path="Wit">?Wit?</category> 
     </categories> 
     -<additional> 
      <field name="delete">?false?</field> 
      <field name="brand">?Amaral?</field> 
      +<field name="short_description"></field> 
      <field name="deliveryTime">?5 werkdagen?</field> 
      <field name="deliveryCosts">?5.?95?</field> 
      +<field name="imageURL_2"></field> 
      +<field name="imageURL_3"></field> 
     </additional> 
    </product> 
+2

1) /products/product [@ categories =「wit」] – Bram 2012-08-15 22:57:03

回答

0

基地/產品/產品

1)只選擇產品記錄與類別= 「威特」

使用

../product[categories/category/@path = 'Wit'] 

2)選擇與非空品牌領域唯一的產品記錄

使用

../product[additional/field[@name='brand' and normalize-space()]] 
0

嘗試這些...

1)/products/product[categories/category/@path='Wit']

2)/products/product[additional/field[@name='brand'][normalize-space()]]

如果你想兩者結合:

/products/product[categories/category/@path='Wit' and additional/field[@name='brand'][normalize-space()]] 
0
<?xml version="1.0" encoding="ISO-8859-1"?> 
<!-- Edited by XMLSpy® --> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="product"> 
With 'Wit': 
<xsl:value-of select="../product[categories/category/@path = 'Wit']/name"/> 
with brandname: 
<xsl:value-of select="../product[additional/field[@name='brand' and normalize-space()]]/name"/> 
</xsl:template> 
</xsl:stylesheet> 

請注意,我只返回產品的名稱。如果您想要返回所有產品詳細信息,只需從'value-of select'中刪除'/ name'即可。