Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hildjj/xmlpug
Transform XML documents with Pug templates
https://github.com/hildjj/xmlpug
Last synced: 28 days ago
JSON representation
Transform XML documents with Pug templates
- Host: GitHub
- URL: https://github.com/hildjj/xmlpug
- Owner: hildjj
- Created: 2016-09-18T21:05:15.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2021-09-07T17:36:21.000Z (about 3 years ago)
- Last Synced: 2024-10-10T23:21:58.830Z (about 1 month ago)
- Language: JavaScript
- Size: 132 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Use [Pug](https://pugjs.org) to transform XML, instead of
[XSLT](http://www.w3.org/TR/xslt). Why? At my office, we call the XSLT book
the *Token of Pain*. Whoever touched the XSLT code last has it on their desk,
and is responsible for being the current expert. That person hates their
life until someone else needs the book badly enough to take on the pain.Also, you can't easily generate HTML5 with XSLT because of the doctype and tags
like `` that don't get closed.# Installation
npm install -g xmlpug
# Example
Write templates like this:
```
doctype html
html
head
meta(charset='utf-8')
meta(name='author', content=$$('front/author/@fullname'))
title= $('front/title/text()')
```where the `$` and `$$` functions perform xpath queries in a source XML document. `$` returns the first match, or `null`. `$$` always returns an array of all of the matches. So given the following XML input:
```
HyperText Markup Language Request For Comments Format
```
the above template would generate:
```
HyperText Markup Language Request For Comments Format
```
# Pug Extensions
The added JavaScript features available in the template are:
- `$(string, element)`: perform an XPath query against the input document, returning the first match. Text nodes are converted to strings, and attribute nodes are converted to the string versions of their values. If no matches are found, returns `null`. If an element is provided, search within that element, otherwise search from the root of the input document.
- `$$(string, element)`: perform an XPath query against the input document, returning all of the matches as an array. Text nodes are converted to strings, and attribute nodes are converted to the string versions of their values. If no matches are found, returns `[]`. If an element is provided, search within that element, otherwise search from the root of the input document.
- `$att(element, string)`: gets the text value of an attribute from an element with the name specified in the string. Returns `null` on errors.
- `$source`: a Buffer containing the original XML source before parsing
- `require(string)`: wrapper around normal node `require` allowing it to work in a template
- `version`: the name and version number of xmlpug# Command Line
Usage: xmlpug [options]
Options:
-h, --help output usage information
-V, --version output the version number
-d, --debug Add Pug debug information
-o, --output [file] Output file
-p, --pretty Pretty print# APIs
Docs coming soon.
[![Tests](https://github.com/hildjj/xmlpug/actions/workflows/node.js.yml/badge.svg)](https://github.com/hildjj/xmlpug/actions/workflows/node.js.yml)
[![codecov](https://codecov.io/gh/hildjj/xmlpug/branch/main/graph/badge.svg?token=FkJe6b3bIS)](https://codecov.io/gh/hildjj/xmlpug)