Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/karurochori/vs-templ

XML static template builder inspired by XSLT
https://github.com/karurochori/vs-templ

Last synced: 3 days ago
JSON representation

XML static template builder inspired by XSLT

Awesome Lists containing this project

README

        

> [!WARNING]
> Migration and adaptation from the other repository is done.
> Documentation and missing features still ongoing.

`vs-templ` is a simple preprocessor for XML files. It can be used statically generate new files from a template definition.
Static templates can be seen as extremely simple programs which are interpreted by this preprocessor. They consume input data also formatted as XML, and generate some output XML file. In theory, it is possible for data to be expressed in other formats (eg. JSON) as well, but at the moment this is not a supported feature.

`vs-templ` was first developed in the context of [vs](https://github.com/karurochori/vs-fltk) to express parametric components.
While the XML ecosystem is often reliant on XSLT as a preprocessor, this option was quickly dismissed for several reasons:

- The rest of the `vs` project is based on `pugixml`. The only XSLT 1.0 implementation which is decently licensed is [libxslt](https://gitlab.gnome.org/GNOME/libxslt) based on [libxml2](https://gitlab.gnome.org/GNOME/libxml2).
Because of that, a trivial integration would have been quite wasteful: an additional serialization and parsing stage is needed to move the tree structure between libraries.
- The scope of XSLT, even in its very first version is too wide & its syntax just verbose. This is mostly a result of `xpath` being too powerful of a tool.
- At some point `vs` will come with dynamic native components, and the idea is for them to match in syntax and behaviour the extended tags introduced by this preprocessor. A custom implementation is the only way to ensure a seamless integration between the two.

Hence, `vs` vendors its own XSLT-ish preprocessor. Still, nothing about its semantics or syntax is directly tied to `vs`. For this reason it is distributed as a separate package, hoping it can reach a wider adoption.

## Examples

### Simple `for` cycle
```xml

Text A
Text B
Text C

```

and

```xml


  • :


```

results in

```xml


  • Value 3: Text C

  • Value 2: Text B

  • Value 1: Text A


```

## Usage
The functionality of this template builder is exposed as a library which can be used for static or dynamic linking.
A self-contained CLI utility is also provided as a frontend.

### As a library
If you want to integrate `vs-templ` in your own application or contribute to its development, [this](./docs/for-developers.md) is where to start.

### Via its CLI
```
vs.tmpl [namespace=`s:`]
```

There is also an alternative format:

```
vs.tmpl [namespace=`s:`]
```

## Syntax
Details about the supported syntax are covered in a [dedicated page](./docs/syntax.md)