diff --git a/ogc/bblocks/known-mimetypes.yaml b/ogc/bblocks/known-mimetypes.yaml index 4a5ad15..b956a46 100644 --- a/ogc/bblocks/known-mimetypes.yaml +++ b/ogc/bblocks/known-mimetypes.yaml @@ -34,6 +34,7 @@ xml: mimeType: application/xml aliases: - application/xml + - text/xml extensions: - xml diff --git a/ogc/bblocks/schemas/transforms.schema.yaml b/ogc/bblocks/schemas/transforms.schema.yaml index 3929005..47354f4 100644 --- a/ogc/bblocks/schemas/transforms.schema.yaml +++ b/ogc/bblocks/schemas/transforms.schema.yaml @@ -69,6 +69,7 @@ $defs: - json-ld-frame - jq - semantic-uplift + - xslt - description: Other identifiers are also accepted $ref: '#/$defs/nonEmptyString' diff --git a/ogc/bblocks/transformers/xslt.py b/ogc/bblocks/transformers/xslt.py new file mode 100644 index 0000000..da93bf6 --- /dev/null +++ b/ogc/bblocks/transformers/xslt.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import json +from typing import AnyStr + +from ogc.bblocks.models import TransformMetadata, Transformer +from lxml import etree + +transform_type = 'xslt' + +default_inputs = [ + 'application/xml', +] + +default_outputs = [ + 'application/xml', +] + +class XmlTransformer(Transformer): + + def __init__(self): + super().__init__(['xslt'], default_inputs, default_outputs) + + def do_transform(self, metadata: TransformMetadata) -> AnyStr | None: + transform = etree.XSLT(etree.XML(metadata.transform_content.encode('utf-8'))) + result = transform(etree.XML(metadata.input_data.encode('utf-8'))) + return etree.tostring(result, encoding='utf-8', pretty_print=True, xml_declaration=True).decode('utf-8') diff --git a/requirements.txt b/requirements.txt index 0c92a2a..1850656 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,7 @@ networkx~=3.1 jq~=1.6 pathvalidate==3.2.0 jsonpointer~=2.4 +lxml~=5.0.0 # mkdocs mkdocs>=1.4.2 @@ -25,4 +26,4 @@ mkdocs-pymdownx-material-extras mkdocs-section-index mkdocstrings mkdocstrings-python -mkdocs-markdownextradata-plugin \ No newline at end of file +mkdocs-markdownextradata-plugin