Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Max Mumford 266 posts 293 karma points
    Sep 26, 2011 @ 16:11
    Max Mumford
    0

    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.

  • Max Mumford 266 posts 293 karma points
    Sep 26, 2011 @ 16:15
    Max Mumford
    0

    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?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 16:20
    Lee Kelleher
    2

    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.

  • Max Mumford 266 posts 293 karma points
    Sep 26, 2011 @ 16:36
    Max Mumford
    0

    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 :) 

  • Max Mumford 266 posts 293 karma points
    Sep 26, 2011 @ 16:36
    Max Mumford
    0

    oops, meant to click your post as the solution of the thread... no way to change it...?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 16:41
    Lee Kelleher
    1

    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.

  • Max Mumford 266 posts 293 karma points
    Sep 26, 2011 @ 16:42
    Max Mumford
    0

    Absolutely. A couple of high fives to make up for it :P

  • Max Mumford 266 posts 293 karma points
    Sep 27, 2011 @ 14:21
    Max Mumford
    0

    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.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 27, 2011 @ 14:33
    Lee Kelleher
    0

    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.

  • Max Mumford 266 posts 293 karma points
    Sep 27, 2011 @ 15:47
    Max Mumford
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft