我需要一个XPath表达式来从多个节点获取值并将它们与'>'连接起来分隔符。
<products>
<product ID="6">
<name>2-in-1 Microsoft Surface Pro 4</name>
<properties>
<property name="subcategories">
<value>Microsoft</value>
</property>
<property name="subsubcategories">
<value>Surface</value>
</property>
<property name="size">
<value></value>
</property>
</properties>
<variations/>
</product>
</products>
我可以从单个节点获取值,如下所示:
properties/property[@name='subcategories']
但是如何组合多个节点,结果如下:
"Microsoft>Surface" (or with a trailing ">" character if that's the only way)
我检查了this post,但是它使用了一个模板,我想要一个XPath表达式(所以我可以使用SelectSingleNode
方法在我的ASP.NET应用程序中对其进行过滤。)
更新1
我试过@ splash58的建议:string-join(//property[@name="subcategories" or @name="subsubcategories"]/value, ">")
但后来我收到了错误:
需要命名空间管理器或XsltContext。这个查询有一个前缀, 变量或用户定义的函数。
Dim responseString As String = "" 'this contains the XML document I load externally
productXML.LoadXml(responseString)
Dim mgr As XmlNamespaceManager = New XmlNamespaceManager(productXML.NameTable)
mgr.AddNamespace("whatever", productXML.DocumentElement.NamespaceURI)
root = productXML.DocumentElement
nodeList = root.SelectNodes("/products/product")
For Each node In nodeList
If node.SelectSingleNode("string-join(//property[@name=""subcategories"" or @name=""subsubcategories""]/value, "">"")") IsNot Nothing Then
'Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.
End If
Next node
如何修复该错误?