def evaluate_as_string(self, context): result = self._evaluate(context) if not isqname(result): raise XUpdateError(XUpdateError.INVALID_QNAME_ATTR, attribute=self._name, value=result) return result
def evaluate_as_nodeset(self, context): arg0, arg1 = self._args # Get the key table key_name = arg0.evaluate_as_string(context) if not isqname(key_name): raise XsltRuntimeError(XsltError.INVALID_QNAME_ARGUMENT, context.instruction, value=key_name) key_name = context.expand_qname(key_name) try: key_documents = context.keys[key_name] except KeyError: # Unknown key name return datatypes.nodeset() else: key_values = key_documents[context.node.xml_root] # Get the lookup value value = arg1.evaluate(context) if isinstance(value, datatypes.nodeset): result = [] for value in value: value = datatypes.string(value) if value in key_values: result.extend(key_values[value]) else: value = datatypes.string(value) if value in key_values: result = key_values[value] else: result = () return datatypes.nodeset(result)
def variable_element(tagname, namespaces, attributes): # required `name` attribute try: name = attributes[None, 'name'] except KeyError: raise XUpdateError(XUpdateError.MISSING_REQUIRED_ATTRIBUTE, element=tagname, attribute='name') else: if not isqname(name): raise XUpdateError(XUpdateError.INVALID_QNAME_ATTR, attribute='name', value=name) prefix, name = splitqname(name) if prefix: try: namespace = namespaces[prefix] except KeyError: raise XUpdateError(XUpdateError.UNDEFINED_PREFIX, prefix=prefix) else: namespace = None name = (namespace, name) # optional `select` attribute if (None, 'select') in attributes: select = attributes[None, 'select'] try: select = parse_expression(select) except XPathError, error: raise XUpdateError(XUpdateError.SYNTAX_ERROR, expression=select, text=str(error))
def prepare(self, element, value): if value is None: if self.default is None: return None value = self.default elif not isqname(value): raise XsltError(XsltError.INVALID_QNAME_ATTR, value=value) return splitqname(value)
def qname(namespace, name): """ Matches a fully qualified name (e.g., xsl:sort) """ assert isqname(name) if ':' in name: local = name[name.index(':') + 1:] else: local = name return ContentModel(ContentModel.TYPE_NAME, (namespace, local), label=name)
def qname(namespace, name): """ Matches a fully qualified name (e.g., xsl:sort) """ assert isqname(name) if ':' in name: local = name[name.index(':')+1:] else: local = name return ContentModel(ContentModel.TYPE_NAME, (namespace, local), label=name)
def prepare(self, element, value): if value is None: if self.default is None: return None value = self.default elif not isqname(value): raise XsltError(XsltError.INVALID_QNAME_ATTR, value=value) prefix, local = splitqname(value) if prefix: try: namespace = element.namespaces[prefix] except KeyError: raise XsltRuntimeException(XsltError.UNDEFINED_PREFIX, elem=element, prefix=prefix) else: namespace = None return (namespace, local)