鉴于此记录结构,我的正确Xpath表达式
base is / products / product
<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>
答案 0 :(得分: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()]]
答案 1 :(得分:0)
base is / products / product
1)仅选择category =“Wit”
的产品记录
使用强>:
../product[categories/category/@path = 'Wit']
2)仅选择非空品牌字段的产品记录
使用强>:
../product[additional/field[@name='brand' and normalize-space()]]
答案 2 :(得分: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>
请注意,我只返回产品的名称。如果您想要退回所有产品详细信息,只需删除&#39; / name&#39;来自选择&#39;的价值。