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]
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]
is working on a reply...