Code sample below demonstrates following:
We have sample extension object with 2 methods
TestMethod - takes XPathNodeIterator as a parameter
TestMethod2 - takes string as a parameter
also we have CustomXmlResolver, stylesheet takes <XML>SourceDoc</XML> as
source XML document
also sylesheet retreives <XML>CustomXmlResolverData</XML> XML document
through the document function and CustomXmlResolver
now we pass $externalDoc/XML node set to both, TestMothod and TestMethod2
I expect output like "CustomXmlResolverData_____CustomXmlResolverDa ta" but
it outputs "SourceDoc_CustomXmlResolverData" !!!
Source document was passed to TestMethod instead of node set returned by the
document function!
I tested this on .Net Framework 1.1.4322 SP1
--- Source ---
using System;
using System.Text;
using System.IO;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace TestApp
{
public class MainClass
{
public MainClass()
{
}
[STAThread]
static void Main(string[] args)
{
XsltArgumentList arg = new XsltArgumentList();
arg.AddExtensionObject("testuri", new SampleExtensionObject());
XslTransform t = new XslTransform();
XPathDocument styleSheet = new XPathDocument(new StringReader(
"<xsl:stylesheet version=\"1.0\"
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:eo=\"testuri\">" +
"<xsl:variable name=\"externalDoc\" select=\"document('uriuriuri')\"/>" +
"<xsl:template match=\"/\">" +
"<xsl:value-of select=\"eo:TestMethod($externalDoc/XML)\"/>___" +
"<xsl:value-of select=\"eo:TestMethod2($externalDoc/XML)\"/>" +
"</xsl:template>" +
"</xsl:stylesheet>"
));
t.Load(styleSheet.CreateNavigator(), null,
typeof(MainClass).Assembly.Evidence);
XPathDocument srcDoc = new XPathDocument(new
StringReader("<XML>SourceDoc</XML>"));
t.Transform(srcDoc, arg, Console.Out, new CustomXmlResolver());
}
}
class CustomXmlResolver : System.Xml.XmlResolver
{
public override object GetEntity(Uri absoluteUri, string role, Type
ofObjectToReturn)
{
return new
MemoryStream(Encoding.Default.GetBytes("<XML>Custo mXmlResolverData</XML>"));
}
public override System.Net.ICredentials Credentials
{
set
{
}
}
}
class SampleExtensionObject
{
public string TestMethod(XPathNodeIterator it)
{
XPathNavigator nav = it.Current;
return nav.Value;
}
public string TestMethod2(string s)
{
return s;
}
}
}