'Transform an element tree with XSLT
@param tree: the element tree
@param stylesheet_path: pathname of the XSLT stylesheet
@param args: dict of arguments to pass to the stylesheet'

def transform(self, tree, stylesheet_path, **args):

    self.error = None
    if args:
        _args = dict(((k, ("'%s'" % args[k])) for k in args))
    else:
        _args = None
    if isinstance(stylesheet_path, (etree._ElementTree, etree._Element)):
        stylesheet = stylesheet_path
    else:
        stylesheet = self.parse(stylesheet_path)
    if (stylesheet is not None):
        try:
            ac = etree.XSLTAccessControl(read_file=True, read_network=True)
            transformer = etree.XSLT(stylesheet, access_control=ac)
            if _args:
                result = transformer(tree, **_args)
            else:
                result = transformer(tree)
            return result
        except:
            e = sys.exc_info()[1]
            self.error = e
            current.log.error(e)
            return None
    else:
        return None
