I need a single XPath expression to get the values from multiple nodes and concatenate them with a '>' separator character.
<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>
I can get the value from a single node like so:
properties/property[@name='subcategories']
But how do I combine multiple nodes so the result would be:
"Microsoft>Surface" (or with a trailing ">" character if that's the only way)
I checked this post, but that uses a template and I want a single XPath expression (so I can filter on it in my ASP.NET application using the SelectSingleNode
method).
update 1
I tried @splash58's suggestion: string-join(//property[@name="subcategories" or @name="subsubcategories"]/value, ">")
But then I get the error:
Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.
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
How can I fix that error?