Skip to content

Commit

Permalink
Merge branch 'OpenWork-NZ-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Nov 28, 2024
2 parents 42b1e5b + 76d2fcc commit 4f83610
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions ogc/bblocks/known-mimetypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ xml:
mimeType: application/xml
aliases:
- application/xml
- text/xml
extensions:
- xml

Expand Down
1 change: 1 addition & 0 deletions ogc/bblocks/schemas/transforms.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ $defs:
- json-ld-frame
- jq
- semantic-uplift
- xslt
- description: Other identifiers are also accepted
$ref: '#/$defs/nonEmptyString'

Expand Down
26 changes: 26 additions & 0 deletions ogc/bblocks/transformers/xslt.py
Original file line number Diff line number Diff line change
@@ -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')
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,4 +26,4 @@ mkdocs-pymdownx-material-extras
mkdocs-section-index
mkdocstrings
mkdocstrings-python
mkdocs-markdownextradata-plugin
mkdocs-markdownextradata-plugin

0 comments on commit 4f83610

Please sign in to comment.