XSL noobie but uttery stuck!
I have a transform that formats a date using c# scripting function , this works fine when I am in VS 2008 and run "show xml output", the output is exactly what I want.
However , when i try to run this using code I get the error
Predefined type 'System.Object' is not defined or imported
To function to call the transform looks like this , it's pretty basic and worked before I started to use scripting
public static string RunXSLT(string xsltFile, string inputXML) { XslCompiledTransform transform = new XslCompiledTransform(); XsltSettings settings = new XsltSettings(); settings.EnableScript = true; transform.Load(xsltFile, settings, null); StringReader sReader = new StringReader(inputXML); XmlTextReader xmlTextReader = new XmlTextReader(sReader); //Create an XmlTextWriter which outputs to memory stream Stream stream = new MemoryStream(); XmlWriter xmlWriter = new XmlTextWriter(stream,> System.Text.Encoding.UTF8); transform.Transform(xmlTextReader, xmlWriter); stream.Position = 0; XmlDocument XmlDoc = new XmlDocument(); XmlDoc.Load(stream); return XmlDoc.OuterXml; }
The XSL transform is this..
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:nlbExtension="urn:nlbExtension" exclude-result-prefixes="msxsl nlbExtension"> <xsl:output method="xml" indent="yes"/> <msxsl:script implements-prefix="nlbExtension" language="C#"> <![CDATA[ public string FormatDateTime(string xsdDateTime, string format) { DateTime date = DateTime.Parse(xsdDateTime); return date.ToString(format); } ]]> </msxsl:script> <xsl:template match="/"> <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" <xsl:for-each select="./Collection/Content" > <url> <loc>http://www.nlb.org<xsl:value-of select="./QuickLink/text()"/></loc> <lastmod><xsl:value-of select="./DateModified/text()" /></lastmod> </url> </xsl:for-each> </urlset> </xsl:template> </xsl:stylesheet>
I know this issue is very old, but maybe this helps someone who is searching for this problem.
I currently became the same compiling error but in totally different topic of C# programming.
I am using Sharp Develop 4.2 and had the same issue. For me the solution was to add "mscorlib" to the references of the project.
This error is a known issue of Microsoft, but dont know the current situation. Just found some discussions from 2010.
Somehow this reference was missing and i do not completely understand at the moment why other projects of me are working without explicit reference to mscorlib, but maybe this indeed is the bug itself ;-)
Best regards Thomas
Cannot reproduce (indeed, you don't actually use the extension in your xslt). I tested it, adding (to the xslt):
<xsl:value-of select="nlbExtension:FormatDateTime(.,'dd MMM yyyy')"/>
and using the input xml:
string xml = new XElement("xml", DateTime.Now).ToString();
And it worked fine (I changed to XmlConvert.ToDateTime
to match xsd format, but it worked OK either way).
If there is a problem, it is in code that you aren't showing us.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With