我喜欢.NET webcontrols和你操作的东西,这是普遍的共识,但是XML和XSL是如此之大,因为你有独立于平台和语言的UI逻辑,所以总有一天我将应用程序更改为php,java或者其他我可以重用所有表示逻辑。 而且,XSL有可能在渲染之前调用.NET(或其他)方法。
你什么时候正常使用XML / XSL? 为什么不经常使用它?
I like .NET webcontrols and you manipulate things, that's common consensus, but XML and XSL is so great, because you have UI logic that is platform & language-independent, so one day I change the app to php, java or whatever and i can reuse all the presentation logic. Moreover, XSL has the possibility to call .NET (or whatever) methods before rendering.
When do you use XML/XSL normally? why no to use it more frequently?
最满意答案
而不是HTML?
我经常使用它来代替asp.net控件,因为它提供了对2.0中V和C的关注点的分离,而你没有在.NET 2.0中获得开箱即用。
显然,有一百万个其他用途与asp.net控件无关。
编辑:实现的草图
public class xsltmanager { /* constructor (singleton) which defines a file watcher for *.xsl in the path of your choice */ //just a mutex for thread safety private object Mutex = new object(); //caching XslCompiledTransforms private Dictionary<string, XslCompiledTransform> cTransforms = new Dictionary<string, XslCompiledTransform>(); public XslCompiledTransform fetch(string identifier) { if (!this.cTransforms.ContainsKey(identifier)) { lock (this.Mutex) { if (!this.cTransforms.ContainsKey(identifier)) { XslCompiledTransform xslDoc = new XslCompiledTransform(); xslDoc.Load(/* file path based on identifier */); this.cTransforms.Add(identifier, xslDoc); } } } return this.cTransforms[identifier]; } /* other util xslt methods - namespace wash, doc merge, whatever */ } public class myPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //get source data XPathDocument xPathDoc = myGetXMLMethod(); //transform params XsltArgumentList oArgs = new XsltArgumentList(); /* add params as required */ //fetching and executing the transform directly to the Response here xsltmanager.instance.get(@"foo\bar\baz").Transform(xPathDoc, oArgs, Response.OutputStream); } }Instead of HTML?
I use it constantly in place of asp.net controls since it affords the separation of concerns for the V and the C in 2.0 that you don't get in .NET 2.0 out of the box.
Obviously there's a million other uses unrelated to asp.net controls.
Edit: a sketch of an implementation
public class xsltmanager { /* constructor (singleton) which defines a file watcher for *.xsl in the path of your choice */ //just a mutex for thread safety private object Mutex = new object(); //caching XslCompiledTransforms private Dictionary<string, XslCompiledTransform> cTransforms = new Dictionary<string, XslCompiledTransform>(); public XslCompiledTransform fetch(string identifier) { if (!this.cTransforms.ContainsKey(identifier)) { lock (this.Mutex) { if (!this.cTransforms.ContainsKey(identifier)) { XslCompiledTransform xslDoc = new XslCompiledTransform(); xslDoc.Load(/* file path based on identifier */); this.cTransforms.Add(identifier, xslDoc); } } } return this.cTransforms[identifier]; } /* other util xslt methods - namespace wash, doc merge, whatever */ } public class myPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //get source data XPathDocument xPathDoc = myGetXMLMethod(); //transform params XsltArgumentList oArgs = new XsltArgumentList(); /* add params as required */ //fetching and executing the transform directly to the Response here xsltmanager.instance.get(@"foo\bar\baz").Transform(xPathDoc, oArgs, Response.OutputStream); } }更多推荐
发布评论