Hi,
I'm in the process of upgrading an asp.net v3.5 web app. to v4 and I'm facing some problems with XSLT transformations I use on XmlDataSource objects.
Part of a XSLT file:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ExtensionObject="ds:ExtensionObject">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/Menus">
<MenuItems>
<xsl:call-template name="MenuListing" />
</MenuItems>
</xsl:template>
<xsl:template name="MenuListing">
<xsl:apply-templates select="Menu" />
</xsl:template>
<xsl:template match="Menu">
<MenuItem>
<xsl:attribute name="Text">
<xsl:value-of select="ExtensionObject:HtmlEncode(MenuTitle)"/>
</xsl:attribute>
<xsl:attribute name="ToolTip">
<xsl:value-of select="MenuTitle"/>
</xsl:attribute>
</MenuItem>
</xsl:template>
</xsl:stylesheet>
And this is the initialization:
xmlDataSource.TransformArgumentList.AddExtensionObject("ds:ExtensionObject", new ExtensionObject());
xmlDataSource.Data = Cache.FetchPageMenu();
ExtensionObject:
public class ExtensionObject {
public static string HtmlEncode(string input) {
return "test";
}
}
I asked a similar question before: http://stackoverflow.com/questions/3409767/net-4-xslt-transformations-broken. The answer was right about the ambiguous call, but even with another correct object it just won't work. I'm not receiving any errors, just no data is displayed.
I've also tried this;
static void test() {
// Create the XslCompiledTransform and load the stylesheet.
XslCompiledTransform xslt = new XslCompiledTransform(true);
xslt.Load(System.Web.Hosting.HostingEnvironment.MapPath("~/transforms/menu.xslt"));
// Create an XsltArgumentList.
XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddExtensionObject("ds:ExtensionObject", new ExtensionObject());
using (XmlWriter w = XmlWriter.Create("output.xml")) {
// Transform the file.
xslt.Transform(Cache.FetchPageMenu(), xslArg, w);
}
}
This works properly in a console application, but in a web application I get a securityexception, again without any further details;
[SecurityException: Request failed.]
System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags) +0
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +323
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
System.Xml.Xsl.XsltOld.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext) +164
MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) +430
I'm running local asp.net v4 IIS7 with full trust.
What can be the problem with the ExtensionObjects. Also, why is it so difficult to debug this, is there a good tool to debug xslt with extension objects?
Thanks agian..