jquery xml based template engine

拥有回忆 提交于 2019-12-11 03:39:52

问题


Judging from the lack of info around, I'm guessing the following question maybe a little "off piste" as they say..

I am trying to find an XML based javascript (pref. JQuery based) templating engine..

A little like say how Ext.JS (Sencha) do things, or SPRY datasets. Something lite..

Obviously there are lots of JSON based ones, and for good reason I know, although I have a requirement that has to use XML.

I have been using John Resig's micro-templating engine for JSON data, and really want something similar for XML based data?

Any ideas? or futile?


回答1:


Okay.. of course XSL templates is probably the obvious thing I was overlooking.. just wanted something as straight forward as JQuery's XML manipulation, but applied to a HTML template.

Settled on www.dhtmlx.com and their AJAX function which does client side XSLT. All seems to work very nicely. A snippet is shown below for anyone who is interested:

Javascript:

dhtmlxAjax.get('/PageTemplates/membernotifications_template.xsl', function (xslLoader) {
        var xmlLoader = dhtmlxAjax.getSync('/ajaxget/getmembernotifications.ashx');
        $('#notifications').html(xmlLoader.doXSLTransToString(xslLoader.xmlDoc.responseXML));
    });

You will need the DHX javascript library of course.. the link is above.

As you can see, we reference the .XSL template and then the actual data source, in my case from a .ashx page which just writes out the XML.

We then, using JQuery (however you could refer to a DOM item directly of course), bind the XSL and XML to output into (in my case) a DIV with ID=notifications.



来源:https://stackoverflow.com/questions/3792634/jquery-xml-based-template-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!