def set_xslt(self, xslt): """ Set the XSLT to use for the transformation. Args: xslt: Returns: """ # set the xslt self.xslt = xslt # parse the xslt xslt_parsed = XSDTree.build_tree(xslt) # set the extension self._set_extension_from_xslt(xslt_parsed) # set the transform self.transformation = XSDTree.transform_to_xslt(xslt_parsed)
def xsl_transform(xml_string, xslt_string): """Apply transformation to xml. Args: xml_string: xslt_string: Returns: """ try: # Build the XSD and XSLT tree xslt_tree = XSDTree.build_tree(xslt_string) xsd_tree = XSDTree.build_tree(xml_string) # Get the XSLT transformation and transform the XSD transform = XSDTree.transform_to_xslt(xslt_tree) transformed_tree = transform(xsd_tree) return str(transformed_tree) except Exception: raise exceptions.CoreError( "An unexpected exception happened while transforming the XML")