2

Is there any client side template engine with XML/ XPath support? I looked into handlebars, mustache, underscore etc. but looks like they only can accept a JSON object as it's context.

What I'm really looking for is to have xpath in expressions:

<div>
   <h1>{{/person/address/street}} </h1>
</div>

Data:

<person>
    <name>Some name</name>
    <address>
        <street>5th Lane</street>
    <address>
</person>

And the JS code like:

Template.render('template.html', data.xml);

I understand it's possible to transform XML to JSON either at client-side or server-side and use handlebars. But I just wanted to avoid this transformation in order to reduce processing time.

Fahim Farook
  • 1,482
  • 2
  • 14
  • 38

1 Answers1

0

The ultimate templating engine that supports XML and XPath is, of course, XSLT, which can be run on the client side.

Also, Saxonica has a library, Saxon-CE, that'll allow XSLT 2.0 to run on web browsers.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • XSLT is not a choice for me as the style-sheet sooner becomes not maintainable and no support for mobile browsers. However why do we need Saxon-CE to run XSTL on web browsers? XSTL is supported by major web browsers and does not require any libraries. – Fahim Farook Oct 25 '15 at 17:47
  • 1
    *Sooner becomes not maintainable*: Not true, but would not encourage its use on browsers over server-side, so do agree with you in that regard. To answer your other question: XSLT 1.0 is supported natively to varying degrees by the major web browsers. XSLT 2.0 is not, but is by Saxon-CE. – kjhughes Oct 25 '15 at 19:21