Copied to clipboard

Flag this post as spam?

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


  • Evan 40 posts 59 karma points
    Jan 14, 2011 @ 06:55
    Evan
    0

    Umbraco Xslt Extension in .Net

    Hi,

    I've written an extenstion in C# that I'm calling from my XSLT. Something like this:

    GetRandomNodeIds()

    And returns something like this

    <nodes>
        <nodeId>1234</nodeId>
        <nodeId>2313</nodeId>
        <nodeId>1118</nodeId>
        <nodeId>2352</nodeId>
    </nodes>

    So that's all working well, but I don't know what datatype my extension should return. I've tried returning it as a string, then doing a exslt:node-set() conversion on it. But that doesn't work. Leaving it as a String doesn't work. And leaving it as a XDocument (which is how it's constructed) doesn't work.

    Anyone else come across this problem before?

    Thanks!

    -Evan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 14, 2011 @ 08:29
    Kim Andersen
    1

    Hi Eran

    I haven't got much experience with developing XSLT extensions (I've used a lot though ;) ), but I think I remember that you shall return it as a "XPathNavigator".

    Does that work or am I totally off?

    /Kim A

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jan 14, 2011 @ 09:21
    Matt Brailsford
    1

    Hey Evan,

    I think (if it's XML you are returning) it needs to be an XPathNodeIterator. Here's an example from one of the provider to my Universal Media Picker

    http://umpp4umb.codeplex.com/SourceControl/changeset/view/d858bf650fdd#TheOutfield.UmbExt.UniversalMediaPicker.Providers.Dropbox%2fDropboxXsltExtension.cs

    Hope this helps

    Matt

  • Evan 40 posts 59 karma points
    Jan 16, 2011 @ 23:47
    Evan
    0

    Thanks a lot guys! I got it working with the XPathNodeIterator. Thanks for the example Matt!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 17, 2011 @ 00:04
    Lee Kelleher
    0

    Hi Evan,

    Curious to how you're getting the random node Ids ... and in what context are you going to use them? (to show random content?)

    On the uComponents project we've got an XSLT extension for RandomNode, that takes a node-set (say $currentPage) and returns a single random node from the collection.  Just thinking that we could include your GetRandomNodeIds extension too? That is if you think it would be useful to others too?

    Cheers, Lee.

  • Evan 40 posts 59 karma points
    Jan 17, 2011 @ 00:36
    Evan
    0

    Yep. Knowing this last Friday probably would have saved me about half a days work..

    Thanks for that Lee.

    uComponents has proved to be really helpful for me already, and I'm only just starting with Umbraco. In the future I'll definitely hunt around ucomponents before I start writing code.

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 17, 2011 @ 00:42
    Lee Kelleher
    0

    Glad you like uComponents.  I know what you mean, its difficult to know what is already available "out there" before you start writing your code.

    We've trying to provide documentation of the various aspects of uComponents - available on CodePlex.  If you do see a gaping hole in the documentation - let us know! :-)

    Only other advice is if you think something "might" already exist for Umbraco, post on the forum (much like you've done here) or use the #umbraco hash-tag on Twitter ... you'll get an answer pretty quick!

    Cheers, Lee.

  • Evan 40 posts 59 karma points
    Jan 17, 2011 @ 00:45
    Evan
    0

    Yeah, I think my problem for this one was I was looking at how to find random nodes via XPath/Xslt in general not specificly to Umbraco, so I didn't stumble upon it :)

    Good advice with the Twitter tag too. I'll give that a go next.

    Thanks again mate :)

  • Evan 40 posts 59 karma points
    Jan 17, 2011 @ 00:45
    Evan
    0

    Oh, and I've foudn the uComponent documentation to be pretty good so far, but will yell out if I see any holes :)

Please Sign in or register to post replies

Write your reply to:

Draft