Copied to clipboard

Flag this post as spam?

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


  • Christian Palm 278 posts 273 karma points
    Jun 08, 2009 @ 15:22
    Christian Palm
    0

    Extension method to umbraco Node: ToXPathNodeIterator()

    Extension method to umbraco Node: ToXPathNodeIterator

    When working with xslt extensions, you need a simple way to return a Node class.
    This Extension Method will help you :-)

    [code]//The extension (Extensions.cs)
    namespace CPalm.Umbraco
    {
    public static class Extensions
    {
    public static XPathNodeIterator ToXPathNodeIterator(this Node node)
    {
    XPathNavigator navigator = content.Instance.XmlContent.CreateNavigator();
    navigator.MoveToId(node.Id.ToString());
    return navigator.Select(".");
    }
    }
    }[/code]

    [code]// Xslt helper class (XsltHelper.cs)
    // Remember to include the using to the namespace where you Extensions is located
    using CPalm.Umbraco;
    namespace CPalm.XsltHelper
    {
    public class XsltHelper
    {
    public static XPathNodeIterator GetNewsContainer()
    {
    Node node = new Node(1000); // Example
    return node.ToXPathNodeIterator();
    }
    }
    }[/code]

    [code]// Xslt sample

    [/code]

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies