开发者

jquery xml based template engine

开发者 https://www.devze.com 2023-01-18 01:26 出处:网络
Judging from the lack of info around, I\'m guessing the following question maybe a little \"off piste\" as they say..

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 mic开发者_StackOverflow社区ro-templating engine for JSON data, and really want something similar for XML based data?

Any ideas? or futile?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消