Custom XSL funcion with XML parameter

How to create custom XSL function with parameter of type XML tree. What is the name of type parameter in the function definition? String or something else?

Example:
public string SignMessage(string xml, string blobCert, string password)

Parameter “string xml” contains XML structure.

You need to use XpathNavigator type to work with an xml input.

See this example of our NodeSet function implementation:

public static XPathNodeIterator NodeSet(XPathNavigator nav)
{
    XPathNodeIterator result = nav.Select("/");
    return result;
}

OK, we change data type to XPathNavigator and return type to XPathNodeIterator. But function still not working.

Cannot convert the operand to ‘Result tree fragment’.
CZ.Advantages.Asap.AsapException: Cannot convert the operand to ‘Result tree fragment’. —> System.Exception: Cannot convert the operand to ‘Result tree fragment’. —> System.Exception: Transformation result invalid. —> System.Xml.XPath.XPathException: Function ‘OR:SignMessage()’ has failed. —> System.Xml.Xsl.XsltException: Cannot convert the operand to ‘Result tree fragment’.
at System.Xml.Xsl.XsltOld.XsltCompileContext.XsltFunctionImpl.ToNavigator(Object argument)
at System.Xml.Xsl.XsltOld.XsltCompileContext.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext)
at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator)
— End of inner exception stack trace —
at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator)
at System.Xml.Xsl.XsltOld.Processor.RunQuery(ActionFrame context, Int32 key)
at System.Xml.Xsl.XsltOld.VariableAction.Execute(Processor processor, ActionFrame frame)
at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor)
at System.Xml.Xsl.XsltOld.Processor.Execute()
at System.Xml.Xsl.XsltOld.ReaderOutput.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at CZ.Advantages.Asap.Rule.OldXsltEngine.Transform(Object engine, XsltArgumentList xslArg, XPathDocument sourceXpathDoc, XmlDocument resultDoc)
at CZ.Advantages.Asap.Rule.MicrosoftXsltEngine.Transform(XmlDocument data, Object xsltEngine, Hashtable parameters, RuleEngine ruleEngine, IDataStructure outputStructure, Boolean validateOnly)
— End of inner exception stack trace —
at CZ.Advantages.Asap.Rule.MicrosoftXsltEngine.Transform(XmlDocument data, Object xsltEngine, Hashtable parameters, RuleEngine ruleEngine, IDataStructure outputStructure, Boolean validateOnly)
— End of inner exception stack trace —
at CZ.Advantages.Asap.Rule.MicrosoftXsltEngine.Transform(XmlDocument data, Object xsltEngine, Hashtable parameters, RuleEngine ruleEngine, IDataStructure outputStructure, Boolean validateOnly)
at CZ.Advantages.Asap.Rule.AbstractXsltEngine.Transform(XmlDocument data, Guid transformationId, Guid retransformationId, Hashtable parameters, Hashtable retransformationParameters, RuleEngine ruleEngine, IDataStructure outputStructure, Boolean validateOnly)
at CZ.Advantages.Asap.Rule.AbstractXsltEngine.Transform(XmlDocument data, Guid transformationId, Hashtable parameters, RuleEngine ruleEngine, IDataStructure outputStructure, Boolean validateOnly)
at CZ.Advantages.Asap.Workflow.TransformationAgent.Run()
at CZ.Advantages.Asap.Workflow.Tasks.ServiceMethodCallEngineTask.OnExecute()
at CZ.Advantages.Asap.Workflow.Tasks.AbstractWorkflowEngineTask.Execute()
— End of inner exception stack trace —

Some hints?

So in your case you need to use XPathNodeIterator as the input parameter type. Or you can use string and use AS:NodeToString() function to convert the XML to string first.