Tritium (programming language)

Last updated
Tritium
Designed by Hampton Catlin
Filename extensions .ts
Website tritium.io
Influenced by
XSLT, Sass (stylesheet language)

Tritium is a simple scripting language for efficiently transforming structured data like HTML, XML, and JSON. It is similar in purpose to XSLT but has a syntax influenced by jQuery, Sass, and CSS versus XSLT's XML based syntax.

Contents

History

Tritium was designed by Hampton Catlin, the creator of languages Sass and Haml and is currently bundled with the Moovweb mobile platform. [1]

As with Sass (created to address deficiencies in CSS) and Haml (created to address deficiencies in coding HTML templates), Catlin designed Tritium to address issues he saw with XSLT while preserving the core benefits of a transformation language. Much of this was based on his prior experience porting Wikipedia's desktop website to the mobile web. [2]

Open Tritium [3] is the open source implementation of the Tritium language. It was presented at O'Reilly Open Source Convention 2014 [4] and the compiler is implemented in Go.

Concept

Tritium takes as input HTML, XML, or JSON documents and outputs HTML, XML, or JSON data that has been transformed according to the rules defined in the Tritium script. Like jQuery, idiomatic Tritium code is structured around selecting a collection of elements via a CSS or XPath selector and then chaining a series of operations on them. [5]

For example, the following script will select all the HTML table elements with id of foo and change their width attributes to 100%.

# Select all HTML nodes that are table elements with ID foo.# The $$() function takes a regular CSS selector$$(“table#foo”){# change the width attributes to “100%”  attribute(“width”, “100%”)}

While Tritium supports both XPath and CSS selectors via the $() and $$() functions (respectively), the preferred usage is XPath. For example, the above code rewritten to use the equivalent XPath selector would be:

# Select all HTML nodes that are table elements with ID foo.# The $() uses XPath$(“//table[@id=’foo’]){# change the width attributes to “100%”  attribute(“width”, “100%”)}

Comparison to XSLT

Both Tritium and XSLT are designed for transforming data. However, Tritium differs in key ways to make it more familiar and easier to use for web developers: [6]

Related Research Articles

<span class="mw-page-title-main">XML</span> Markup language by the W3C for encoding of data

Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The World Wide Web Consortium's XML 1.0 Specification of 1998 and several other related specifications—all of them free open standards—define XML.

XSLT is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG. Support for JSON and plain-text transformation was added in later updates to the XSLT 1.0 specification.

An HTML element is a type of HTML document component, one of several types of HTML nodes. The first used version of HTML was written by Tim Berners-Lee in 1993 and there have since been many versions of HTML. The most commonly used version is HTML 4.01, which became official standard in December 1999. An HTML document is composed of a tree of simple HTML nodes, such as text nodes, and HTML elements, which add semantics and formatting to parts of document. Each element can have HTML attributes specified. Elements can also have content, including other elements and text.

XForms is an XML format used for collecting inputs from web forms. XForms was designed to be the next generation of HTML / XHTML forms, but is generic enough that it can also be used in a standalone manner or with presentation languages other than XHTML to describe a user interface and a set of common data manipulation tasks.

XSL-FO is a markup language for XML document formatting that is most often used to generate PDF files. XSL-FO is part of XSL, a set of W3C technologies designed for the transformation and formatting of XML data. The other parts of XSL are XSLT and XPath. Version 1.1 of XSL-FO was published in 2006.

An XML editor is a markup language editor with added functionality to facilitate the editing of XML. This can be done using a plain text editor, with all the code visible, but XML editors have added facilities like tag completion and menus and buttons for tasks that are common in XML editing, based on data supplied with document type definition (DTD) or the XML tree.

In computer hypertext, a URI fragment is a string of characters that refers to a resource that is subordinate to another, primary resource. The primary resource is identified by a Uniform Resource Identifier (URI), and the fragment identifier points to the subordinate resource.

Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a Web application.

<span class="mw-page-title-main">XMLSpy</span> XML and JSON editing integrated development environment

XMLSpy is a proprietary XML editor and integrated development environment (IDE) developed by Altova. XMLSpy allows developers to create XML-based and Web services applications using technologies such as XML, JSON, XBRL, XML Schema, XSLT, XPath, XQuery, WSDL and SOAP.

In computing, the two primary stylesheet languages are Cascading Style Sheets (CSS) and the Extensible Stylesheet Language (XSL). While they are both called stylesheet languages, they have very different purposes and ways of going about their tasks.

<span class="mw-page-title-main">Oxygen XML Editor</span>

The Oxygen XML Editor is a multi-platform XML editor, XSLT/XQuery debugger and profiler with Unicode support. It is a Java application so it can run in Windows, Mac OS X, and Linux. It also has a version that can run as an Eclipse plugin.

jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of Aug 2022, jQuery is used by 77% of the 10 million most popular websites. Web analysis indicates that it is the most widely deployed JavaScript library by a large margin, having at least 3 to 4 times more usage than any other JavaScript library.

JsonML, the JSON Markup Language is a lightweight markup language used to map between XML and JSON. It converts an XML document or fragment into a JSON data structure for ease of use within JavaScript environments such as a web browser, allowing manipulation of XML data without the overhead of an XML parser.

Haml is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Haml gives the flexibility to have some dynamic content in HTML. Similar to other template systems like eRuby, Haml also embeds some code that gets executed during runtime and generates HTML code in order to provide some dynamic content. In order to run Haml code, files need to have a .haml extension. These files are similar to .erb or eRuby files which also help to embed Ruby code while developing a web application.

Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages. It mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.

XPath is an expression language designed to support the query or transformation of XML documents. It was defined by the World Wide Web Consortium (W3C) and can be used to compute values from the content of an XML document. Support for XPath exists in applications that support XML, such as web browsers, and many programming languages.

<span class="mw-page-title-main">Sass (stylesheet language)</span> Stylesheet language

Sass is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS). SassScript is the scripting language itself.

XQuery is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats. The language is developed by the XML Query working group of the W3C. The work is closely coordinated with the development of XSLT by the XSL Working Group; the two groups share responsibility for XPath, which is a subset of XQuery.

<span class="mw-page-title-main">XML transformation language</span> Type of programming language

An XML transformation language is a programming language designed specifically to transform an input XML document into an output document which satisfies some specific goal.

Diazo, previously named xdv, is a general-purpose, open source website theming tool. It is written in Python and generates XSLT. Diazo creates a separation between theme pages and transformation rules, allowing web designers to work on templates in plain HTML, without knowledge of XSLT or special template-related codes.

References

  1. C. Coyier, D. Rupert. (2013-05-30). "Episode 070". ShopTalkShow. Retrieved 2013-07-10.
  2. D. Nugent (2013-05-07). "Interview with Hampton Catlin". HTML5 Developer Conference. Retrieved 2013-07-10.
  3. "Open Tritium". Moovweb. 2014-07-24. Archived from the original on 2015-01-19. Retrieved 2015-01-19.
  4. "Mobile and Multi-Device Web Development with Tritium". O'Reilly. 2014-07-24. Retrieved 2015-01-19.
  5. I. Anand (2013-04-30). "From Desktop to Mobile". Future Insights Live - Las Vegas, 2013. Retrieved 2013-07-10.
  6. I. Anand (2014-02-06). "Applying Transformations to Responsive Web Design". Smashing Magazine. Retrieved 2014-02-07.