XSLT now return prettified output
This commit is contained in:
@@ -2,7 +2,7 @@ from lxml import etree
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
def format(source: str, prettify: bool) -> str:
|
||||
def formatXML(source: str, prettify: bool) -> str:
|
||||
"""Method used to format XML
|
||||
|
||||
:param source: XML to format
|
||||
@@ -85,17 +85,17 @@ def xsd(source: str, xsd: str) -> bool:
|
||||
|
||||
def xslt(source: str, xslt: str) -> str:
|
||||
"""
|
||||
Method used to transformate XML string using XSLT
|
||||
Method used to transform XML string using XSLT
|
||||
|
||||
:param source: XML string to transform
|
||||
:param xslt: XSLT string used to transformate XML
|
||||
:param xslt: XSLT string used to transform XML
|
||||
:return: Result of transformation
|
||||
"""
|
||||
xslt_input = BytesIO(xslt.encode("utf-8"))
|
||||
xslt_transform = etree.XSLT(etree.parse(xslt_input).getroot())
|
||||
xslt_transform = etree.XSLT(etree.parse(xslt_input))
|
||||
|
||||
document_input = BytesIO(source.encode("utf-8"))
|
||||
xml = etree.parse(document_input).getroot()
|
||||
|
||||
result = xml.xslt(xslt_transform).decode()
|
||||
return result
|
||||
transformed = str(xslt_transform(xml))
|
||||
return formatXML(transformed, True)
|
||||
@@ -37,9 +37,9 @@ def process_xml(request: request, type: str) -> str:
|
||||
elif (type == "xpath"):
|
||||
response_json['result'] = Parser.xpath(data, process)
|
||||
elif (type == "prettify"):
|
||||
response_json['result'] = Parser.format(data, True)
|
||||
response_json['result'] = Parser.formatXML(data, True)
|
||||
elif (type == "minimize"):
|
||||
response_json['result'] = Parser.format(data, False)
|
||||
response_json['result'] = Parser.formatXML(data, False)
|
||||
else:
|
||||
raise ValueError("Valid operation types are: xsd, xslt, xpath")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user