love Silverlight 2.0, it just makes sense to a c# hack such as myself but with aspirations of reducing server side load to a minimum I had the bright idea of moving XSL operations to the client... All I need is the compact runtime XSL libraries... Hmm... I've got rich XML support... Where's the bloody XSL??
Please if anyone finds it call me a muppet and point me in the right direction. Still it's an opportunity for a workaround (otherwise known as hack :)
Simple task: leverage Javascript XSL capabilities within Silverlight in an interesting way.
/// Internet Explorer protected override ScriptObject LoadXml(string xml) { ScriptObject scriptObj = HtmlPage.Window.CreateInstance("ActiveXObject", new object[] { "Microsoft.XMLDOM" }); if ((bool)scriptObj.Invoke("loadXml", new object[] { xml })) { return scriptObj; } else { throw new ArgumentException("XmlDocument could not be generated from string", "xml"); } } /// Mozilla/Safari protected override ScriptObject LoadXml(string xml) { ScriptObject scriptObj = HtmlPage.Window.CreateInstance("DOMParser", null); return scriptObj.Invoke("parseFromString", new object[] { xml, "text/xml" }) as ScriptObject; }
/// Internet Explorer public override string Transform(string xmlData) { string transformationResult = string.Empty; ScriptObject xmlObj = LoadXml(xmlData); transformationResult = xmlObj.Invoke("transformNode", this.XslDataObj) as string; return transformationResult; } /// Mozilla/Safari public override string Transform(string xmlData) { string transformationResult = String.Empty; ScriptObject xmlObj = LoadXml(xmlData); ScriptObject processor = HtmlPage.Window.CreateInstance("XSLTProcessor"); processor.Invoke("importStylesheet", new object[] { this.XslDataObj }); ScriptObject processorResult = processor.Invoke("transformToDocument", new object[] { xmlObj, HtmlPage.Window.GetProperty("document") }) as ScriptObject; ScriptObject serializer = HtmlPage.Window.CreateInstance("XMLSerializer"); transformationResult = serializer.Invoke("serializeToString", new object[] { processorResult }) as string; return transformationResult; }
Currently rated 1.8 by 2719 people
- Currently 1.772846/5 Stars.
- 1
- 2
- 3
- 4
- 5