In a recent project, I was able to use the following syntax to get distinct values from my XML file:
<xsl:for-each select="distinct-values($ds/datasource/Products-list/Products/CategoryName)">
But now, we are migrating the project to ASP.NET and the following code does not work:
public DataSourceManager manager = new DataSourceManager();
protected void Page_Load(object sender, EventArgs e)
{
this.manager.Get("http:***",
"distinct-values(/datasource/Products-list/Products/CategoryName)",
new String[] { "." }, this.messageRepeater);
}
}
The Get function looks like:
public void Get(String datasourceUrl,
String xpathToNodes,
Array nodeNames,
Repeater repeater,
params String[] options ) {
Debug.WriteLine("datasourceUrl= " + datasourceUrl);
Debug.WriteLine("xpathToNodes= " + xpathToNodes);
//call datasource url
XmlDocument doc = new XmlDocument();
doc.Load(datasourceUrl);
//statusCode
this.statusCode = doc.SelectSingleNode("/datasource/result/status/@code").Value;
if (options.GetLength(0) > 0) {
this.maxItem = Convert.ToInt16(options[0]);
}
//iterate
this.list = new ArrayList();
int count = 0;
if (IsErrorCode == false) {
XmlNodeList nodes = doc.SelectNodes(xpathToNodes);
foreach (XmlNode node in nodes) {
Hashtable row = new Hashtable();
foreach (String nodeName in nodeNames) {
row.Add(nodeName, node.SelectSingleNode(nodeName).InnerText);
}
list.Add(row);
if (++count == this.maxItem) {
break;
}
}
}
//data binding
repeater.DataSource = list;
repeater.DataBind();
}
The error returned is the following:
Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.
How can I get distinct values in ASP.NET?