Last active
December 22, 2015 11:28
-
-
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')"/>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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