def Evaluate(context, string): """ The dyn:evaluate function evaluates a string as an XPath expression and returns the resulting value, which might be a boolean, number, string, node set, result tree fragment or external object. The sole argument is the string to be evaluated. If the string is an invalid XPath expression, an empty node-set is returned. http://www.exslt.org/dyn/functions/evaluate/index.html """ string = Conversions.StringValue(string) p = parser.new() try: result = p.parse(string).evaluate(context) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % ( string, tb.getvalue()) context.processor.warning(msg) result = [] except: import traceback traceback.print_exc() result = [] return result
def Map(context, nodeset, string): """ The dyn:map function evaluates the expression passed as the second argument for each of the nodes passed as the first argument, and returns a node set of those values. http://www.exslt.org/dyn/functions/map/index.html """ if type(nodeset) != type([]): raise XsltRuntimeException(Error.WRONG_ARGUMENT_TYPE, context.currentInstruction) string = Conversions.StringValue(string) try: expr = parser.new().parse(string) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % (string, tb.getvalue()) context.processor.warning(msg) return [] return MapImpl(context, nodeset, expr)
def Sum(context, nodeset, string): """ The dyn:sum function calculates the sum for the nodes passed as the first argument, where the value of each node is calculated dynamically using an XPath expression passed as a string as the second argument. http://www.exslt.org/dyn/functions/sum/index.html """ if type(nodeset) != type([]): raise XsltRuntimeException(Error.WRONG_ARGUMENT_TYPE, context.currentInstruction) string = Conversions.StringValue(string) try: expr = parser.new().parse(string) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % (string, tb.getvalue()) context.processor.warning(msg) return [] return sum([ Conversions.NumberValue(n) for n in MapImpl(context, nodeset, expr) ])
def Closure(context, nodeset, string): """ The dyn:closure function creates a node set resulting from transitive closure of evaluating the expression passed as the second argument on each of the nodes passed as the first argument, then on the node set resulting from that and so on until no more nodes are found. http://www.exslt.org/dyn/functions/closure/index.html """ if type(nodeset) != type([]): raise XsltRuntimeException(Error.WRONG_ARGUMENT_TYPE, context.currentInstruction) string = Conversions.StringValue(string) try: expr = parser.new().parse(string) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % (string, tb.getvalue()) context.processor.warning(msg) return [] return ClosureImpl(context, nodeset, expr, [])
def Map(context, nodeset, string): """ The dyn:map function evaluates the expression passed as the second argument for each of the nodes passed as the first argument, and returns a node set of those values. http://www.exslt.org/dyn/functions/map/index.html """ if type(nodeset) != type([]): raise XsltRuntimeException(Error.WRONG_ARGUMENT_TYPE, context.currentInstruction) string = Conversions.StringValue(string) try: expr = parser.new().parse(string) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % ( string, tb.getvalue()) context.processor.warning(msg) return [] return MapImpl(context, nodeset, expr)
def Sum(context, nodeset, string): """ The dyn:sum function calculates the sum for the nodes passed as the first argument, where the value of each node is calculated dynamically using an XPath expression passed as a string as the second argument. http://www.exslt.org/dyn/functions/sum/index.html """ if type(nodeset) != type([]): raise XsltRuntimeException(Error.WRONG_ARGUMENT_TYPE, context.currentInstruction) string = Conversions.StringValue(string) try: expr = parser.new().parse(string) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % ( string, tb.getvalue()) context.processor.warning(msg) return [] return sum( [Conversions.NumberValue(n) for n in MapImpl(context, nodeset, expr)])
def Closure(context, nodeset, string): """ The dyn:closure function creates a node set resulting from transitive closure of evaluating the expression passed as the second argument on each of the nodes passed as the first argument, then on the node set resulting from that and so on until no more nodes are found. http://www.exslt.org/dyn/functions/closure/index.html """ if type(nodeset) != type([]): raise XsltRuntimeException(Error.WRONG_ARGUMENT_TYPE, context.currentInstruction) string = Conversions.StringValue(string) try: expr = parser.new().parse(string) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % ( string, tb.getvalue()) context.processor.warning(msg) return [] return ClosureImpl(context, nodeset, expr, [])
def Evaluate(context, string): """ The dyn:evaluate function evaluates a string as an XPath expression and returns the resulting value, which might be a boolean, number, string, node set, result tree fragment or external object. The sole argument is the string to be evaluated. If the string is an invalid XPath expression, an empty node-set is returned. http://www.exslt.org/dyn/functions/evaluate/index.html """ string = Conversions.StringValue(string) p = parser.new() try: result = p.parse(string).evaluate(context) except SyntaxError: tb = handle_traceback() msg = 'Syntax error in XPath "%s", masked by empty node set return:\n%s' % (string, tb.getvalue()) context.processor.warning(msg) result = [] except: import traceback traceback.print_exc() result = [] return result
Classes that support validation and evaluation of attribute values in XSLT instruction elements Copyright 2003 Fourthought, Inc. (USA). Detailed license and copyright information: http://4suite.org/COPYRIGHT Project home, documentation, distributions: http://4suite.org/ """ from Ft import TranslateMessage as _ import cStringIO, traceback from Ft.Xml.XPath import Conversions from Ft.Xml.XPath import RuntimeException as XPathRuntimeException from Ft.Xml.XPath import parser _xpath_parser = parser.new() from Ft.Xml.Xslt import XsltException, XsltRuntimeException, Error from Ft.Xml.Xslt import parser _xpattern_parser = parser.new() del parser from Ft.Xml import XML_NAMESPACE, XMLNS_NAMESPACE, EMPTY_NAMESPACE from Ft.Xml.Lib.XmlString import IsQName, SplitQName from AttributeValueTemplate import AttributeValueTemplate class AttributeInfo: display = 'unknown'
def parseExpression(self, expression): if expression is None: return None #import sys; print >>sys.stderr, 'exp', expression return parser.new().parse(expression)