def instantiate(self, context, processor): origState = context.copy() context.setNamespaces(self._nss) name = self._name.evaluate(context) namespace = self._namespace.evaluate(context) (prefix, local) = xml.dom.ext.SplitQName(name) if not namespace and prefix: namespace = context.processorNss[prefix] #FIXME: Use proper pysax AttributeList objects processor.writers[-1].startElement(name, namespace) for attr_set_name in self._useAttributeSets: split_name = Util.ExpandQName(attr_set_name, namespaces=context.processorNss) try: attr_set = processor.attributeSets[split_name] except KeyError: raise XsltException(Error.UNDEFINED_ATTRIBUTE_SET, attr_set_name) attr_set.use(context, processor) for child in self.childNodes: context = child.instantiate(context, processor)[0] processor.writers[-1].endElement(name) context.set(origState) return (context, )
def setup(self): self.__dict__['_nss'] = xml.dom.ext.GetAllNs(self) mode_attr = self.getAttributeNS(EMPTY_NAMESPACE, 'mode') if mode_attr == '': self.__dict__['_mode'] = None else: split_name = Util.ExpandQName(mode_attr, namespaces=self._nss) self.__dict__['_mode'] = split_name select = self.getAttributeNS(EMPTY_NAMESPACE, 'select') if select: parser = XPathParser.XPathParser() self.__dict__['_expr'] = parser.parseExpression(select) else: self.__dict__['_expr'] = None self.__dict__['_sortSpecs'] = [] self.__dict__['_params'] = [] for child in self.childNodes: #All children should be sort and with-param if child.namespaceURI == XSL_NAMESPACE: if child.localName == 'sort': self._sortSpecs.append(child) elif child.localName == 'with-param': self._params.append(child) else: raise XsltException(Error.ILLEGAL_APPLYTEMPLATE_CHILD) else: raise XsltException(Error.ILLEGAL_APPLYTEMPLATE_CHILD) return
def setup(self): self.__dict__['_nss'] = xml.dom.ext.GetAllNs(self) self.__dict__['_match'] = self.getAttributeNS(EMPTY_NAMESPACE, 'match') mode_attr = self.getAttributeNS(EMPTY_NAMESPACE, 'mode') if not mode_attr: self.__dict__['_mode'] = None else: split_name = Util.ExpandQName(mode_attr, namespaces=self._nss) self.__dict__['_mode'] = split_name name_attr = self.getAttributeNS(EMPTY_NAMESPACE, 'name') split_name = Util.ExpandQName(name_attr, namespaces=self._nss) self.__dict__['_name'] = split_name self.__dict__['_params'] = [] self.__dict__['_elements'] = [] for child in self.childNodes: if child.namespaceURI == XSL_NAMESPACE: if child.localName == 'param': self.__dict__['_params'].append(child) elif child.localName in ['choose', 'if']: self.__dict__['_elements'].append((1, child)) else: self.__dict__['_elements'].append((0, child)) else: self.__dict__['_elements'].append((0, child)) #A list of tuples #(pattern,qmatch,priority) #either pattern or qmatch will be present but not both self.__dict__['_patternInfo'] = [] if self._match: priority = self.getAttributeNS(EMPTY_NAMESPACE, 'priority') or None if priority is not None: try: priority = float(priority) except: raise XsltException(Error.ILLEGAL_TEMPLATE_PRIORITY) parser = XPatternParser.XPatternParser() shortcuts = parser.parsePattern(self._match).getMatchShortcuts() for pattern, (shortcut, extra_arg) in shortcuts: if priority is None: tpl_priority = pattern.priority else: tpl_priority = priority self.__dict__['_patternInfo'].append( (shortcut, extra_arg, tpl_priority))
def ElementAvailable(context, qname): split_name = Util.ExpandQName(Conversions.StringValue(qname), namespaces=context.processorNss) if g_extElements.has_key( split_name) or CoreFunctions.CoreFunctions.has_key(split_name): return CoreFunctions. True (context) else: return CoreFunctions. False (context)
def instantiate(self, context, processor): origState = context.copy() context.setNamespaces(self._nss) split_name = Util.ExpandQName(self._name, namespaces=self._nss) processor.attributeSets[split_name] = self self._varBindings = context.varBindings context.set(origState) return (context, )
def Key(context, qname, keyList): result = [] name = Util.ExpandQName(Conversions.StringValue(qname), namespaces=context.processorNss) if context.stylesheet.keys.has_key(name): a_dict = context.stylesheet.keys[name] if type(keyList) != type([]): keyList = [keyList] for key in keyList: key = Conversions.StringValue(key) result = result + a_dict.get(key, []) return result
def setup(self): self._nss = xml.dom.ext.GetAllNs(self) name_attr = self.getAttributeNS(EMPTY_NAMESPACE, 'name') split_name = Util.ExpandQName(name_attr, namespaces=self._nss) self._name = split_name self._select = self.getAttributeNS(EMPTY_NAMESPACE, 'select') if self._select: parser = XPathParser.XPathParser() self._expr = parser.parseExpression(self._select) else: self._expr = None return
def FormatNumber(context, number, formatString, decimalFormatName=None): decimal_format = '' num = Conversions.NumberValue(number) format_string = Conversions.StringValue(formatString) if decimalFormatName is not None: split_name = Util.ExpandQName(decimalFormatName, namespaces=context.processorNss) decimal_format = context.stylesheet.decimalFormats[split_name] else: decimal_format = context.stylesheet.decimalFormats[''] from Ft.Lib import routines result = routines.FormatNumber(num, format_string) return result
def SystemProperty(context, qname): uri, lname = Util.ExpandQName(Conversions.StringValue(qname), namespaces=context.processorNss) if uri == XSL_NAMESPACE: if lname == 'version': return 1.0 if lname == 'vendor': return "Fourthought Inc." if lname == 'vendor-url': return "http://4Suite.org" elif uri == 'http://xmlns.4suite.org/xslt/env-system-property': return os.environ.get(lname, '') elif uri == 'http://xmlns.4suite.org': if lname == 'version': return __version__ return ''
def instantiate(self, context, processor): origState = context.copy() context.setNamespaces(self._nss) node = context.node if node.nodeType == Node.TEXT_NODE: processor.writers[-1].text(node.data) elif node.nodeType == Node.ELEMENT_NODE: #FIXME: Use proper pysax AttributeList objects processor.writers[-1].startElement(node.nodeName, node.namespaceURI) for attr_set_name in self._useAttributeSets: split_name = Util.ExpandQName(attr_set_name, namespaces=context.processorNss) try: attr_set = processor.attributeSets[split_name] except KeyError: raise XsltException(Error.UNDEFINED_ATTRIBUTE_SET, attr_set_name) attr_set.use(context, processor) for child in self.childNodes: context = child.instantiate(context, processor)[0] processor.writers[-1].endElement(node.nodeName) elif node.nodeType == Node.DOCUMENT_NODE: for child in self.childNodes: context = child.instantiate(context, processor)[0] elif node.nodeType == Node.ATTRIBUTE_NODE: if node.namespaceURI == XMLNS_NAMESPACE: nodeName = 'xmlns' + (node.localName and ':' + node.localName) processor.writers[-1].attribute(nodeName, node.nodeValue, node.namespaceURI) else: processor.writers[-1].attribute(node.nodeName, node.nodeValue, node.namespaceURI) elif node.nodeType == Node.PROCESSING_INSTRUCTION_NODE: processor.writers[-1].processingInstruction(node.target, node.data) elif node.nodeType == Node.COMMENT_NODE: processor.writers[-1].comment(node.data) else: raise Exception("Unknown Node Type %d" % node.nodeType) context.set(origState) return (context,)
def use(self, context, processor, used=None): if used is None: used = [] origState = context.copy() context.varBindings = self._varBindings for attr_set_name in self._useAttributeSets: split_name = Util.ExpandQName(attr_set_name, namespaces=context.processorNss) try: attr_set = processor.attributeSets[split_name] except KeyError: raise XsltException(Error.UNDEFINED_ATTRIBUTE_SET, attr_set_name) attr_set.use(context, processor) for child in self.childNodes: context = child.instantiate(context, processor)[0] context.set(origState) return context
def instantiate(self, context, processor): origState = context.copy() context.setNamespaces(self._nss) processor.writers[-1].startElement(self._aliasNodeName, self._aliasUri, self._outputNss) for (name, uri, avt) in self.__attrs: value = avt.evaluate(context) processor.writers[-1].attribute(name, value, uri) for attr_set_name in self._useAttributeSets: split_name = Util.ExpandQName(attr_set_name, namespaces=context.processorNss) try: attr_set = processor.attributeSets[split_name] except KeyError: raise XsltException(Error.UNDEFINED_ATTRIBUTE_SET, attr_set_name) attr_set.use(context, processor) for child in self.childNodes: context = child.instantiate(context, processor)[0] processor.writers[-1].endElement(self._aliasNodeName) context.set(origState) return (context, )
def _instantiateMode(self, context): rt = self._mode.evaluate(context) split_name = Util.ExpandQName(rt, namespaces=self._nss) return split_name