From: Sapan Bhatia Date: Tue, 15 Sep 2009 15:39:36 +0000 (+0000) Subject: Integrated XSLT processors. X-Git-Tag: sfa-0.9-2~17 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=f17d257364748630be54d23293c6def022e2a75b Integrated XSLT processors. --- diff --git a/sfatables/exec.py b/sfatables/exec.py index 778d73d8..5d096b6f 100644 --- a/sfatables/exec.py +++ b/sfatables/exec.py @@ -24,7 +24,7 @@ class SFATablesRules: def apply(self, rspec): intermediate_rspec = rspec for rule in self.sorted_rule_list: - intermediate_rspec = rule.apply(intermediate_rspec) + intermediate_rspec = rule.apply_interpreted(intermediate_rspec) return intermediate_rspec diff --git a/sfatables/xmlrule.py b/sfatables/xmlrule.py index d787c15e..381b5871 100644 --- a/sfatables/xmlrule.py +++ b/sfatables/xmlrule.py @@ -11,6 +11,45 @@ class XMLRule: processors = {'match':None,'target':None} context = {'match':None,'target':None} + def apply_processor(self, type, rspec): + processor = processors[type] + styledoc = libxml2.parseFile(processor) + style = libxslt.parseStylesheetDoc(styledoc) + doc = libxml2.parseDoc(rspec) + result = style.applyStylesheet(doc, None) + processed_result = style.saveResultToString(result, 0) + style.freeStylesheet() + doc.freeDoc() + result.freeDoc() + + return stylesheet_result + + def match(self, rspec): + match_result = self.apply_processor('match',rspec) + return (match_result=='True') + + def target(self, rspec): + target_result = self.apply_processor('target',rspec) + return target_result + + def apply_interpreted(self, rspec): + # Interpreted + # + # output = + # if (match(match_args, rspec) + # then target(target_args, rspec) + # else rspec + + if (self.match(rspec)): + return self.target(rspec) + else: + return rspec + + + def apply_compiled(rspec): + # Not supported yet + return None + def load_xml_extension (self, type, chain, rule_number): filename = sfatables_config+"/"+chain+"/"+"sfatables-%d-%s"%(rule_number,type)