Select top 5 "rows" in XML -file
-
is there any way to make a selection of the top 5 (or any number) rows with certain attributes. I'm used to SQL language and have tried some of the xml features for this too but haven´t seen anything about selecting a certain number of "rows". Anyone who knows? Regards M
-
is there any way to make a selection of the top 5 (or any number) rows with certain attributes. I'm used to SQL language and have tried some of the xml features for this too but haven´t seen anything about selecting a certain number of "rows". Anyone who knows? Regards M
You can use XPath to contruct a query, then depending on what language you are using to implement this you could (C# exmample):
public XmlNodeList Search(string input)
{
string query = "/mainnode/subnode/[name = " + input.Trim().ToString() + "]";
XmlDocument doc = new XmlDocument();
doc.Load("mydata.xml");
XmlNodeList nodes = doc.SelectNodes(query);
return nodes;
}Then just iterate through your return
XmlNodeList
5 times. I suppose there are other ways to do this, this is just a quick example. -Nick Parker -
is there any way to make a selection of the top 5 (or any number) rows with certain attributes. I'm used to SQL language and have tried some of the xml features for this too but haven´t seen anything about selecting a certain number of "rows". Anyone who knows? Regards M
Yep, the "pure" xsl solution will be using
position()
I believe, like this:"/store/books[position() <= 5]"
This will select 5 first books Philip Patrick Web-site: www.stpworks.com "Two beer or not two beer?" Shakesbeer