Select nodes where <list of node ids> contains <node id>
Hi all,
I have a list of node ID's from a database and I want to use umbraco's GetXmlNodeByXPath method to return the corresponding nodes. Here is my query string:
"//Agency[@isDoc and contains('1119 ', @id)]"
But nothing is returned! (I have double checked that a node with the id 1119 does infact exist!) If I remove the contains function, all nodes of that type are returned.
Update: If I remove the speech marks from around the list of node ID's it works. This suggests its a problem that the @id returns an int and so fails when comparing it to a string? How can I convert the @id to a string in xslt?
The 'persistOrder' parameter is there for if you are bothered about the ordering of the nodes. It's basically a performance thing, faster to get the nodes in whichever way the XPath query gets them, or fractionally slower to get them in the correct order. (Seriously, it's tiny bit fractionally slower).
I ideally need to have some other xpath attribute selectors in the xpath statement along with specifying a list of node ids. Is the source for uComponents available so I can edit the method to allow for other xpath selectors? Or can you explain how I would achieve this without the use of the uComponents package?
Great, thanks for the links. There are a couple of different routes I can take with the problem I am working on at the moment and one of them involves using a modified version of the ucomponents method so thanks for the source.
I think it would be a useful feature for people to be able to specify additional attributes in the query and perhaps even customise the first half of the xpath query (i.e. //doctype/descendent-of-self::* [@id = x or @id = y] sort of thing.
Select nodes where <list of node ids> contains <node id>
Hi all,
I have a list of node ID's from a database and I want to use umbraco's GetXmlNodeByXPath method to return the corresponding nodes. Here is my query string:
"//Agency[@isDoc and contains('1119 ', @id)]"
But nothing is returned! (I have double checked that a node with the id 1119 does infact exist!) If I remove the contains function, all nodes of that type are returned.
Any ideas what the problem is?
Max.
Update: If I remove the speech marks from around the list of node ID's it works. This suggests its a problem that the @id returns an int and so fails when comparing it to a string? How can I convert the @id to a string in xslt?
Hi Max,
Are you trying to get a node-set from a comma-seperated list of node IDs? If so, are you using uComponents?
In the Nodes XSLT extension of uComponents there is a method called "GetXmlNodeByCsv(string csv, bool persistOrder)".
The 'persistOrder' parameter is there for if you are bothered about the ordering of the nodes. It's basically a performance thing, faster to get the nodes in whichever way the XPath query gets them, or fractionally slower to get them in the correct order. (Seriously, it's tiny bit fractionally slower).
Cheers, Lee.
That did it, thanks!
Installed the package
Referenced the uComponents.Core dll in my VS usercontrols project
Intellisense picked it up and we were ready to go :)
oops, meant to click your post as the solution of the thread... no way to change it...?
Glad you got it sorted. uComponents to the rescue! :-)
No worries about the solution, future readers will figure it out... and I've got waaay more karma points that I need!
Cheers, Lee.
Absolutely. A couple of high fives to make up for it :P
Hi again Lee,
I ideally need to have some other xpath attribute selectors in the xpath statement along with specifying a list of node ids. Is the source for uComponents available so I can edit the method to allow for other xpath selectors? Or can you explain how I would achieve this without the use of the uComponents package?
Thanks,
Max.
Hi Max,
uComponents source is available here: http://ucomponents.codeplex.com/SourceControl/list/changesets - it's all MIT licensed, so you can do as you please.
As for the XPath, I'm thinking of 2 things:
1. Take a look at the Xml XSLT extension (again in uComponents) called FilterNodes.
2. We could extend the GetXmlNodeByCsv to take an optional 3rd parameter for XPath expression ... hmmm (but wouldn't be available until next release)
Cheers, Lee.
Great, thanks for the links. There are a couple of different routes I can take with the problem I am working on at the moment and one of them involves using a modified version of the ucomponents method so thanks for the source.
I think it would be a useful feature for people to be able to specify additional attributes in the query and perhaps even customise the first half of the xpath query (i.e. //doctype/descendent-of-self::* [@id = x or @id = y] sort of thing.
Cheers!
is working on a reply...