Skip to content

Instantly share code, notes, and snippets.

@vladox
Last active December 22, 2015 11:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vladox/6465465 to your computer and use it in GitHub Desktop.
XmlPrime Native Module to dynamically resolve xpath expressions inside a XSLT usage: <xsl:copy-of select="ext:evaluate(.,'./somenode')"/>
using System.Collections.Generic;
using System.Xml.Schema;
using System.Xml.XPath;
namespace XmlPrime.Samples.XsltModule
{
[XdmModule("http://www.xmlprime.com/xpath")]
public class EvaluateExtensionModule
{
[XdmFunction("evaluate")]
[XdmType(XmlTypeCode.Item, Quantifier.ZeroOrMore)]
public static IEnumerable<XPathItem> Evaluate([XdmType(XmlTypeCode.Item)] XPathItem contextitem, [XdmType(XmlTypeCode.String)] string xpathExp)
{
// We can then compile the expression using the Compile method.
// This returns us an XPath object encapsulating the query.
var xpath = XPath.Compile(xpathExp);
// We call the XPath.Evaluate method to evaluate the expression.
// This returns a enumeration of XPathItems.
return xpath.Evaluate(contextitem);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment