Skip to main content

A framework for XML transformations without boilerplate.

Project description

inxs – A Python framework for XML transformations without boilerplate.

inxs is inexcessive.

inxs is not XSLT.

inxs is ISC-licensed.

inxs is fully documented here: https://inxs.readthedocs.io/en/latest/

https://img.shields.io/pypi/v/inxs.svg https://img.shields.io/pypi/l/inxs.svg https://img.shields.io/pypi/pyversions/inxs.svg https://img.shields.io/travis/funkyfuture/inxs/master.svg https://coveralls.io/repos/github/funkyfuture/inxs/badge.svg

At a glimpse

Solving the Wikipedia XSLT example #1:

def extract_person(element):
    return element.attrib['username'], element.find('name').text

def append_person(previous_result, result):
    lxml_utils.subelement(result, 'name', {'username': previous_result[0]},
                          text=previous_result[1])

transformation = Transformation(
    Rule('person', (extract_person, append_person)),
    result_object='context.result', context={'result': etree.Element('root')})

# that's five (or not counting line-breaks: nine) lines less sloc
# than the XSLT implementation

Solving the Wikipedia XSLT example #2:

def generate_skeleton(context, e):
    context.persons_list = e.ul()
    context.html = e.html(
        e.head(e.title('Testing XML Example')),
        e.body(e.h1('Persons'), context.persons_list))

def extract_person(element, persons):
    persons.append((element.find('name').text, element.find('family-name').text))

def list_persons(previous_result, persons_list, e):
    persons_list.extend(e.li(f'{x[1]}, {x[0]}') for x in previous_result)

transformation = Transformation(
    lib.init_elementmaker(namespace='http://www.w3.org/1999/xhtml'),
    generate_skeleton,
    Rule('person', extract_person),
    lib.sorter('persons', itemgetter(1)),
    list_persons,
    result_object='context.html', context={'persons': []})

# that's eight (or not counting line-breaks: thirteen) lines less sloc
# than the XSLT implementation

Here you can find the source repository and issue tracker of inxs.

History

0.1b1 (2017-06-25)

  • new: Allows the definition that any rule must match per transformation as common_rule_conditions.

  • Minor improvements and fixes.

0.1b0 (2017-06-19)

  • First beta release.

0.1a0 (2017-05-02)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inxs-0.1b2.dev10.tar.gz (19.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page