JavaScript Template Language Transformations (JTLT, pronounced as "Jetlet")—a JavaScript equivalent of XSLT, for JSON/JavaScript object data sources.
As with XSLT, allows for declarative, linear declaration of (recursive) templates and can be transformed into different formats (e.g., HTML strings, JSON, DOM objects, etc.).
Early alpha state!!!
Packaged with JSONPath Plus.
The sample file is from http://goessner.net/articles/JsonPath/
npm install .
In the browser, you will also need to include the dependencies. See the test file.
See the docs.
JTLT, having the freedom to start a new pattern from XSLT, and though seeking to learn from it, deviates somewhat from making an exact equivalence with XSLT (to the extent JTLT and JSONPath implement what could possibly be transferred to JSON-based transformations from XSLT):
- Although the option is given for throwing errors upon finding templates of equal priority, the default behavior is to give preference to the last template (unlike XSLT which makes it an error by default).
-
Document and add test cases to cover current features!
-
Implement and demo equivalent to applying and calling templates, and root template
-
Demo chaining of methods, including equivalents to XQuery's FLWOR expressions (see also Promises to-do), perhaps even making aliases so that XQuery's friendlier terms can be used instead of XSLT's.
-
-
Support processing of JSON documents with
$jtlt-stylesheet
to let documents define their own targeted stylesheets. -
When sufficiently documented, add as example library/tool to JSONPath wiki.
-
Allow alternative to
element()
,array()
, etc. methods by just detecting those types from return values (and generic of each type likedom()
andjson()
). -
Allow, depending on mode, containers to contain containers of other types (e.g., a JS container containing DOM objects, or temporary use of a string container, etc.).
-
Add
appendResult(function () {return result})
. -
Add JSON update functions (equivalent to Xquery Update Facility for XML (overview)) and create JSON serialization (as with XSLT expressed itself in declarative XML) so one can submit and evaluate through HTTPQuery (and also supply to JSONEditor, etc.). Utilize updating by reference.
-
Make schema-aware so that templates could target types. Most reusable application may be having a type-driven view of a JSON Schema instance (e.g., dates could be shown inside a calendar widget). Perhaps this schema-awareness could also drive a JSON editor (as with other existing projects) (even using same API as JSONEditor?) (or type-aware filtered search/raw queries). This would help not only for editors which edit a JSON file in full, but also for providing schema paths or other identifiers so that a transformed/queried subset of a file (or joining of multiple files) could point the way for edited contents to be saved back to the correct JSON file and position in the JSON file.
-
Add a non-eval PR for JSONPath. The OR condition (outside of filters) is another important feature as would be schema-aware path results.
-
Allow hybrid JSON/Jamilih or JSON/(X)HTML/XML so that one can add XPath or query into HTML in a relevant manner
-
Support pull parsing/streaming? Pass
done()
function to templates to signal completion? -
Support Promise API in addition to callbacks (reconcile with current chaining; see also XQuery FLWOR to-do)
-
Add XQuery Functions (also supporting DOM and JSON where possible) as plug-in (also any missing from XSLT/XQuery 3.0). Also add, if not present among these functions (or in XQuery), add equivalents to XSLT's
document()
andunparsed-text()
for allowing non-JSON file retrieval (as well as variables/parameters) and also methods for iterating or retrieving IndexedDB,localStorage
, and cookies (names, keys and values). -
Add
outputType
which uses a DOM joiner but allows specialized serialized output (e.g., pretty-printed HTML) so the users don't need to build it themselves (likewise with stringified JSON output). -
See code for other possible to-dos