# # Functions from module extensions # def debugDumpExtensions(output): """Dumps a list of the registered XSLT extension functions and elements""" libxsltmod.xsltDebugDumpExtensions(output) def registerTestModule(): """Registers the test module""" libxsltmod.xsltRegisterTestModule() def unregisterExtModule(URI): """Unregister an XSLT extension module from the library.""" ret = libxsltmod.xsltUnregisterExtModule(URI) return ret def unregisterExtModuleElement(name, URI): """Unregisters an extension module element""" ret = libxsltmod.xsltUnregisterExtModuleElement(name, URI) return ret def unregisterExtModuleFunction(name, URI): """Unregisters an extension module function""" ret = libxsltmod.xsltUnregisterExtModuleFunction(name, URI) return ret def unregisterExtModuleTopLevel(name, URI): """Unregisters an extension module top-level element""" ret = libxsltmod.xsltUnregisterExtModuleTopLevel(name, URI) return ret # # Functions from module extra # def registerAllExtras(): """Registers the built-in extensions""" libxsltmod.xsltRegisterAllExtras() # # Functions from module python # def pythonCleanup(): """Cleanup just libxslt (not libxml2) memory allocated""" libxsltmod.xsltPythonCleanup() def registerErrorHandler(f, ctx): """Register a Python written function to for error reporting. The function is called back as f(ctx, error).""" ret = libxsltmod.xsltRegisterErrorHandler(f, ctx) return ret def registerExtModuleElement(name, URI, precompile, transform): """Register a Python written element to the XSLT engine""" ret = libxsltmod.xsltRegisterExtModuleElement(name, URI, precompile, transform) return ret def registerExtModuleFunction(name, URI, f): """Register a Python written function to the XSLT engine""" ret = libxsltmod.xsltRegisterExtModuleFunction(name, URI, f) return ret def registerExtensionClass(URI, c): """Register a Python written extension class to the XSLT engine""" ret = libxsltmod.xsltRegisterExtensionClass(URI, c) return ret def setLoaderFunc(loader): """Set the function for controlling document loading""" ret = libxsltmod.xsltSetLoaderFunc(loader) return ret # # Functions from module xslt # def cleanupGlobals(): """Unregister all global variables set up by the XSLT library""" libxsltmod.xsltCleanupGlobals() def init(): """Initializes the processor (e.g. registers built-in extensions, etc.)""" libxsltmod.xsltInit() # # Functions from module xsltInternals # def isBlank(str): """Check if a string is ignorable""" ret = libxsltmod.xsltIsBlank(str) return ret def loadStylesheetPI(doc): """This function tries to locate the stylesheet PI in the given document If found, and if contained within the document, it will extract that subtree to build the stylesheet to process @doc (doc itself will be modified). If found but referencing an external document it will attempt to load it and generate a stylesheet from it. In both cases, the resulting stylesheet and the document need to be freed once the transformation is done.""" if doc == None: doc__o = None else: doc__o = doc._o ret = libxsltmod.xsltLoadStylesheetPI(doc__o) if ret == None: return None return stylesheet(_obj=ret) def newStylesheet(): """Create a new XSLT Stylesheet""" ret = libxsltmod.xsltNewStylesheet() if ret == None: return None return stylesheet(_obj=ret) def parseStylesheetDoc(doc): """parse an XSLT stylesheet building the associated structures""" if doc == None: doc__o = None else: doc__o = doc._o ret = libxsltmod.xsltParseStylesheetDoc(doc__o) if ret == None: return None return stylesheet(_obj=ret) def parseStylesheetFile(filename): """Load and parse an XSLT stylesheet""" ret = libxsltmod.xsltParseStylesheetFile(filename) if ret == None: return None return stylesheet(_obj=ret) def uninit(): """Uninitializes the processor.""" libxsltmod.xsltUninit() # # Functions from module xsltutils # def calibrateAdjust(delta): """Used for to correct the calibration for xsltTimestamp()""" libxsltmod.xsltCalibrateAdjust(delta) def debuggerStatus(): """Get xslDebugStatus.""" ret = libxsltmod.xsltGetDebuggerStatus() return ret def nsProp(node, name, nameSpace): """Similar to xmlGetNsProp() but with a slightly different semantic Search and get the value of an attribute associated to a node This attribute has to be anchored in the namespace specified, or has no namespace and the element is in that namespace. This does the entity substitution. This function looks in DTD attribute declaration for #FIXED or default declaration values unless DTD use has been turned off.""" if node == None: node__o = None else: node__o = node._o ret = libxsltmod.xsltGetNsProp(node__o, name, nameSpace) return ret def setDebuggerStatus(value): """This function sets the value of xslDebugStatus.""" libxsltmod.xsltSetDebuggerStatus(value) def timestamp(): """Used for gathering profiling data""" ret = libxsltmod.xsltTimestamp() return ret def xslDropCall(): """Drop the topmost item off the call stack""" libxsltmod.xslDropCall() class xpathParserContext(libxml2.xpathParserContext): def __init__(self, _obj=None): self._o = None libxml2.xpathParserContext.__init__(self, _obj=_obj) # accessors for xpathParserContext def context(self): """Get the xpathContext from an xpathParserContext""" ret = libxsltmod.xsltXPathParserGetContext(self._o) if ret == None: return None return xpathContext(_obj=ret) # # xpathParserContext functions from module extra # def functionNodeSet(self, nargs): """Implement the node-set() XSLT function node-set node-set(result-tree) This function is available in libxslt, saxon or xt namespace.""" libxsltmod.xsltFunctionNodeSet(self._o, nargs) # # xpathParserContext functions from module functions # def documentFunction(self, nargs): """Implement the document() XSLT function node-set document(object, node-set?)""" libxsltmod.xsltDocumentFunction(self._o, nargs) def elementAvailableFunction(self, nargs): """Implement the element-available() XSLT function boolean element-available(string)""" libxsltmod.xsltElementAvailableFunction(self._o, nargs) def formatNumberFunction(self, nargs): """Implement the format-number() XSLT function string format-number(number, string, string?)""" libxsltmod.xsltFormatNumberFunction(self._o, nargs) def functionAvailableFunction(self, nargs): """Implement the function-available() XSLT function boolean function-available(string)""" libxsltmod.xsltFunctionAvailableFunction(self._o, nargs) def generateIdFunction(self, nargs): """Implement the generate-id() XSLT function string generate-id(node-set?)""" libxsltmod.xsltGenerateIdFunction(self._o, nargs) def keyFunction(self, nargs): """Implement the key() XSLT function node-set key(string, object)""" libxsltmod.xsltKeyFunction(self._o, nargs) def systemPropertyFunction(self, nargs): """Implement the system-property() XSLT function object system-property(string)""" libxsltmod.xsltSystemPropertyFunction(self._o, nargs) def unparsedEntityURIFunction(self, nargs): """Implement the unparsed-entity-uri() XSLT function string unparsed-entity-uri(string)""" libxsltmod.xsltUnparsedEntityURIFunction(self._o, nargs) class xpathContext(libxml2.xpathContext): def __init__(self, _obj=None): self._o = None libxml2.xpathContext.__init__(self, _obj=_obj) def __del__(self): pass # accessors for xpathContext def transformContext(self): """Get the transformation context from an xpathContext""" ret = libxsltmod.xsltXPathGetTransformContext(self._o) if ret == None: return None return transformCtxt(_obj=ret) # # xpathContext functions from module functions # def registerAllFunctions(self): """Registers all default XSLT functions in this context""" libxsltmod.xsltRegisterAllFunctions(self._o) class transformCtxt(transformCtxtBase): def __init__(self, _obj=None): self._o = None transformCtxtBase.__init__(self, _obj=_obj) # accessors for transformCtxt def context(self): """Get the XPath context of a transformation""" ret = libxsltmod.xsltTransformGetContext(self._o) if ret == None: return None return xpathContext(_obj=ret) def current(self): """Get the current() node of a transformation""" ret = libxsltmod.xsltTransformGetCurrent(self._o) if ret == None: return None return libxml2.xmlNode(_obj=ret) def insertNode(self): """Get the insertion node in the output document""" ret = libxsltmod.xsltTransformGetInsertNode(self._o) if ret == None: return None return libxml2.xmlNode(_obj=ret) def instruction(self): """Get the instruction node in the stylesheet""" ret = libxsltmod.xsltTransformGetInstruction(self._o) if ret == None: return None return libxml2.xmlNode(_obj=ret) def mode(self): """Get the mode of a transformation""" ret = libxsltmod.xsltTransformGetMode(self._o) return ret def modeURI(self): """Get the mode URI of a transformation""" ret = libxsltmod.xsltTransformGetModeURI(self._o) return ret def outputDoc(self): """Get the output document of a transformation""" ret = libxsltmod.xsltTransformGetOutputDoc(self._o) if ret == None: return None return libxml2.xmlDoc(_obj=ret) def outputURI(self): """Get the output URI of a transformation if known""" ret = libxsltmod.xsltTransformGetOutputURI(self._o) return ret def style(self): """Get the stylesheet from a transformation""" ret = libxsltmod.xsltTransformGetStyle(self._o) if ret == None: return None return stylesheet(_obj=ret) # # transformCtxt functions from module attributes # def applyAttributeSet(self, node, inst, attrSets): """Apply the xsl:use-attribute-sets. If @attrSets is None, then @inst will be used to exctract this value. If both, @attrSets and @inst, are None, then this will do nothing.""" if node == None: node__o = None else: node__o = node._o if inst == None: inst__o = None else: inst__o = inst._o libxsltmod.xsltApplyAttributeSet(self._o, node__o, inst__o, attrSets) # # transformCtxt functions from module documents # def freeDocuments(self): """Free up all the space used by the loaded documents""" libxsltmod.xsltFreeDocuments(self._o) # # transformCtxt functions from module extensions # def freeCtxtExts(self): """Free the XSLT extension data""" libxsltmod.xsltFreeCtxtExts(self._o) def initCtxtExts(self): """Initialize the set of modules with registered stylesheet data""" ret = libxsltmod.xsltInitCtxtExts(self._o) return ret def shutdownCtxtExts(self): """Shutdown the set of modules loaded""" libxsltmod.xsltShutdownCtxtExts(self._o) # # transformCtxt functions from module extra # def debug(self, node, inst, comp): """Process an debug node""" if node == None: node__o = None else: node__o = node._o if inst == None: inst__o = None else: inst__o = inst._o libxsltmod.xsltDebug(self._o, node__o, inst__o, comp) def registerExtras(self): """Registers the built-in extensions. This function is deprecated, use xsltRegisterAllExtras instead.""" libxsltmod.xsltRegisterExtras(self._o) # # transformCtxt functions from module imports # def findElemSpaceHandling(self, node): """Find strip-space or preserve-space informations for an element respect the import precedence or the wildcards""" if node == None: node__o = None else: node__o = node._o ret = libxsltmod.xsltFindElemSpaceHandling(self._o, node__o) return ret def needElemSpaceHandling(self): """Checks whether that stylesheet requires white-space stripping""" ret = libxsltmod.xsltNeedElemSpaceHandling(self._o) return ret # # transformCtxt functions from module namespaces # def copyNamespace(self, elem, ns): """Copies a namespace node (declaration). If @elem is not None, then the new namespace will be declared on @elem.""" if elem == None: elem__o = None else: elem__o = elem._o if ns == None: ns__o = None else: ns__o = ns._o ret = libxsltmod.xsltCopyNamespace(self._o, elem__o, ns__o) if ret == None: return None return libxml2.xmlNs(_obj=ret) def copyNamespaceList(self, node, cur): """Do a copy of an namespace list. If @node is non-None the new namespaces are added automatically. This handles namespaces aliases. This function is intended only for *internal* use at transformation-time for copying ns-declarations of Literal Result Elements. Called by: xsltCopyTreeInternal() (transform.c) xsltShallowCopyElem() (transform.c) REVISIT: This function won't be used in the refactored code.""" if node == None: node__o = None else: node__o = node._o if cur == None: cur__o = None else: cur__o = cur._o ret = libxsltmod.xsltCopyNamespaceList(self._o, node__o, cur__o) if ret == None: return None return libxml2.xmlNs(_obj=ret) def namespace(self, cur, ns, out): """Find a matching (prefix and ns-name) ns-declaration for the requested @ns->prefix and @ns->href in the result tree. If none is found then a new ns-declaration will be added to @resultElem. If, in this case, the given prefix is already in use, then a ns-declaration with a modified ns-prefix be we created. Called by: - xsltCopyPropList() (*not* anymore) - xsltShallowCopyElement() - xsltCopyTreeInternal() (*not* anymore) - xsltApplySequenceConstructor() (*not* in the refactored code), - xsltElement() (*not* anymore)""" if cur == None: cur__o = None else: cur__o = cur._o if ns == None: ns__o = None else: ns__o = ns._o if out == None: out__o = None else: out__o = out._o ret = libxsltmod.xsltGetNamespace(self._o, cur__o, ns__o, out__o) if ret == None: return None return libxml2.xmlNs(_obj=ret) def plainNamespace(self, cur, ns, out): """Obsolete. *Not* called by any Libxslt/Libexslt function. Exaclty the same as xsltGetNamespace().""" if cur == None: cur__o = None else: cur__o = cur._o if ns == None: ns__o = None else: ns__o = ns._o if out == None: out__o = None else: out__o = out._o ret = libxsltmod.xsltGetPlainNamespace(self._o, cur__o, ns__o, out__o) if ret == None: return None return libxml2.xmlNs(_obj=ret) def specialNamespace(self, invocNode, nsName, nsPrefix, target): """Find a matching (prefix and ns-name) ns-declaration for the requested @nsName and @nsPrefix in the result tree. If none is found then a new ns-declaration will be added to @resultElem. If, in this case, the given prefix is already in use, then a ns-declaration with a modified ns-prefix be we created. Note that this function's priority is to preserve ns-prefixes; it will only change a prefix if there's a namespace clash. If both @nsName and @nsPrefix are None, then this will try to "undeclare" a default namespace by declaring an xmlns="".""" if invocNode == None: invocNode__o = None else: invocNode__o = invocNode._o if target == None: target__o = None else: target__o = target._o ret = libxsltmod.xsltGetSpecialNamespace(self._o, invocNode__o, nsName, nsPrefix, target__o) if ret == None: return None return libxml2.xmlNs(_obj=ret) # # transformCtxt functions from module python # def compareTransformContextsEqual(self, other): """Compare one transformCtxt with another""" if other == None: other__o = None else: other__o = other._o ret = libxsltmod.xsltCompareTransformContextsEqual(self._o, other__o) return ret def freeTransformContext(self): """Free up an existing XSLT TransformContext""" libxsltmod.xsltFreeTransformContext(self._o) def transformContextHashCode(self): """Get the hash code of the transformContext""" ret = libxsltmod.xsltGetTransformContextHashCode(self._o) return ret # # transformCtxt functions from module templates # def attrListTemplateProcess(self, target, attrs): """Processes all attributes of a Literal Result Element. Attribute references are applied via xsl:use-attribute-set attributes. Copies all non XSLT-attributes over to the @target element and evaluates Attribute Value Templates. Called by xsltApplySequenceConstructor() (transform.c).""" if target == None: target__o = None else: target__o = target._o if attrs == None: attrs__o = None else: attrs__o = attrs._o ret = libxsltmod.xsltAttrListTemplateProcess(self._o, target__o, attrs__o) if ret == None: return None return libxml2.xmlAttr(_obj=ret) def attrTemplateProcess(self, target, attr): """Process one attribute of a Literal Result Element (in the stylesheet). Evaluates Attribute Value Templates and copies the attribute over to the result element. This does *not* process attribute sets (xsl:use-attribute-set).""" if target == None: target__o = None else: target__o = target._o if attr == None: attr__o = None else: attr__o = attr._o ret = libxsltmod.xsltAttrTemplateProcess(self._o, target__o, attr__o) if ret == None: return None return libxml2.xmlAttr(_obj=ret) def attrTemplateValueProcess(self, str): """Process the given node and return the new string value.""" ret = libxsltmod.xsltAttrTemplateValueProcess(self._o, str) return ret def attrTemplateValueProcessNode(self, str, inst): """Process the given string, allowing to pass a namespace mapping context and return the new string value. Called by: - xsltAttrTemplateValueProcess() (templates.c) - xsltEvalAttrValueTemplate() (templates.c) QUESTION: Why is this function public? It is not used outside of templates.c.""" if inst == None: inst__o = None else: inst__o = inst._o ret = libxsltmod.xsltAttrTemplateValueProcessNode(self._o, str, inst__o) return ret def evalAttrValueTemplate(self, inst, name, ns): """Evaluate a attribute value template, i.e. the attribute value can contain expressions contained in curly braces ({}) and those are substituted by they computed value.""" if inst == None: inst__o = None else: inst__o = inst._o ret = libxsltmod.xsltEvalAttrValueTemplate(self._o, inst__o, name, ns) return ret def evalTemplateString(self, contextNode, inst): """Processes the sequence constructor of the given instruction on @contextNode and converts the resulting tree to a string. This is needed by e.g. xsl:comment and xsl:processing-instruction.""" if contextNode == None: contextNode__o = None else: contextNode__o = contextNode._o if inst == None: inst__o = None else: inst__o = inst._o ret = libxsltmod.xsltEvalTemplateString(self._o, contextNode__o, inst__o) return ret # # transformCtxt functions from module variables # def evalGlobalVariables(self): """Evaluates all global variables and parameters of a stylesheet. For internal use only. This is called at start of a transformation.""" ret = libxsltmod.xsltEvalGlobalVariables(self._o) return ret def evalOneUserParam(self, name, value): """This is normally called from xsltEvalUserParams to process a single parameter from a list of parameters. The @value is evaluated as an XPath expression and the result is stored in the context's global variable/parameter hash table. To have a parameter treated literally (not as an XPath expression) use xsltQuoteUserParams (or xsltQuoteOneUserParam). For more details see description of xsltProcessOneUserParamInternal.""" ret = libxsltmod.xsltEvalOneUserParam(self._o, name, value) return ret def freeGlobalVariables(self): """Free up the data associated to the global variables its value.""" libxsltmod.xsltFreeGlobalVariables(self._o) def parseStylesheetParam(self, cur): """Registers a local XSLT 'param' declaration at transformation time and evaluates its value.""" if cur == None: cur__o = None else: cur__o = cur._o libxsltmod.xsltParseStylesheetParam(self._o, cur__o) def parseStylesheetVariable(self, inst): """Registers a local XSLT 'variable' instruction at transformation time and evaluates its value.""" if inst == None: inst__o = None else: inst__o = inst._o libxsltmod.xsltParseStylesheetVariable(self._o, inst__o) def quoteOneUserParam(self, name, value): """This is normally called from xsltQuoteUserParams to process a single parameter from a list of parameters. The @value is stored in the context's global variable/parameter hash table.""" ret = libxsltmod.xsltQuoteOneUserParam(self._o, name, value) return ret def variableLookup(self, name, ns_uri): """Search in the Variable array of the context for the given variable value.""" ret = libxsltmod.xsltVariableLookup(self._o, name, ns_uri) if ret == None: return None return libxml2.xpathObjectRet(ret) # # transformCtxt functions from module xsltInternals # def allocateExtraCtxt(self): """Allocate an extra runtime information slot at run-time and return its number This make sure there is a slot ready in the transformation context""" ret = libxsltmod.xsltAllocateExtraCtxt(self._o) return ret def createRVT(self): """Creates a Result Value Tree (the XSLT 1.0 term for this is "Result Tree Fragment")""" ret = libxsltmod.xsltCreateRVT(self._o) if ret == None: return None return libxml2.xmlDoc(_obj=ret) def extensionInstructionResultFinalize(self): """Finalizes the data (e.g. result tree fragments) created within a value-returning process (e.g. EXSLT's function). Tree fragments marked as being returned by a function are set to normal state, which means that the fragment garbage collector will free them after the function-calling process exits.""" ret = libxsltmod.xsltExtensionInstructionResultFinalize(self._o) return ret def freeRVTs(self): """Frees all registered result value trees (Result Tree Fragments) of the transformation. Internal function; should not be called by user-code.""" libxsltmod.xsltFreeRVTs(self._o) def registerLocalRVT(self, RVT): """Registers a result value tree (XSLT 1.0 term: Result Tree Fragment) in the RVT garbage collector. The fragment will be freed when the instruction which created the fragment exits.""" if RVT == None: RVT__o = None else: RVT__o = RVT._o ret = libxsltmod.xsltRegisterLocalRVT(self._o, RVT__o) return ret def registerPersistRVT(self, RVT): """Register the result value tree (XSLT 1.0 term: Result Tree Fragment) in the fragment garbage collector. The fragment will be freed when the transformation context is freed.""" if RVT == None: RVT__o = None else: RVT__o = RVT._o ret = libxsltmod.xsltRegisterPersistRVT(self._o, RVT__o) return ret def registerTmpRVT(self, RVT): """Registers the result value tree (XSLT 1.0 term: Result Tree Fragment) in the garbage collector. The fragment will be freed at the exit of the currently instantiated xsl:template. Obsolete; this function might produce massive memory overhead, since the fragment is only freed when the current xsl:template exits. Use xsltRegisterLocalRVT() instead.""" if RVT == None: RVT__o = None else: RVT__o = RVT._o ret = libxsltmod.xsltRegisterTmpRVT(self._o, RVT__o) return ret def releaseRVT(self, RVT): """Either frees the RVT (which is an xmlDoc) or stores it in the context's cache for later reuse.""" if RVT == None: RVT__o = None else: RVT__o = RVT._o libxsltmod.xsltReleaseRVT(self._o, RVT__o) # # transformCtxt functions from module xsltutils # def message(self, node, inst): """Process and xsl:message construct""" if node == None: node__o = None else: node__o = node._o if inst == None: inst__o = None else: inst__o = inst._o libxsltmod.xsltMessage(self._o, node__o, inst__o) def printErrorContext(self, style, node): """Display the context of an error.""" if style == None: style__o = None else: style__o = style._o if node == None: node__o = None else: node__o = node._o libxsltmod.xsltPrintErrorContext(self._o, style__o, node__o) def profileInformation(self): """This function should be called after the transformation completed to extract template processing profiling informations if availble. The informations are returned as an XML document tree like