home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 March / PCWELT_3_2006.ISO / base / 04_xap_libs.mo / usr / lib / python2.4 / site-packages / libxslt.py < prev    next >
Encoding:
Python Source  |  2005-04-11  |  38.6 KB  |  1,162 lines

  1. #
  2. # Both libxml2mod and libxsltmod have a dependancy on libxml2.so
  3. # and they should share the same module, try to convince the python
  4. # loader to work in that mode if feasible
  5. #
  6. import sys
  7. if not hasattr(sys,'getdlopenflags'):
  8.     import libxml2mod
  9.     import libxsltmod
  10.     import libxml2
  11. else:
  12.     try:
  13.         from dl import RTLD_GLOBAL, RTLD_NOW
  14.     except ImportError:
  15.         RTLD_GLOBAL = -1
  16.         RTLD_NOW = -1
  17.         try:
  18.             import os
  19.             osname = os.uname()[0]
  20.             if osname == 'Linux' or osname == 'SunOS':
  21.                 RTLD_GLOBAL = 0x00100
  22.                 RTLD_NOW = 0x00002
  23.         elif osname == 'Darwin':
  24.             RTLD_GLOBAL = 0x8
  25.         RTLD_NOW = 0x2
  26.             #
  27.             # is there a better method ?
  28.             #
  29. #            else:
  30. #                print "libxslt could not guess RTLD_GLOBAL and RTLD_NOW " + \
  31. #                      "on this platform: %s" % (osname)
  32.         except:
  33.          pass
  34. #            print "libxslt could not guess RTLD_GLOBAL and RTLD_NOW " + \
  35. #                  "on this platform: %s" % (osname)
  36.     except:
  37.      RTLD_GLOBAL = -1
  38.      RTLD_NOW = -1
  39.  
  40.     if RTLD_GLOBAL != -1 and RTLD_NOW != -1:
  41.         try:
  42.             flags = sys.getdlopenflags() 
  43.             sys.setdlopenflags(RTLD_GLOBAL | RTLD_NOW)
  44.             try:
  45.                 import libxml2mod
  46.                 import libxsltmod
  47.                 import libxml2
  48.             finally:
  49.                 sys.setdlopenflags(flags)
  50.         except:
  51.             import libxml2mod
  52.             import libxsltmod
  53.             import libxml2
  54.     else:
  55.         import libxml2mod
  56.         import libxsltmod
  57.         import libxml2
  58.  
  59. class extensionModule:
  60.     def _styleInit(self, style, URI):
  61.         return self.styleInit(stylesheet(_obj=style), URI)
  62.  
  63.     def _styleShutdown(self, style, URI, data):
  64.         return self.styleShutdown(stylesheet(_obj=style), URI, data)
  65.  
  66.     def _ctxtInit(self, ctxt, URI):
  67.         return self.ctxtInit(transformCtxt(_obj=ctxt), URI)
  68.  
  69.     def _ctxtShutdown(self, ctxt, URI, data):
  70.         return self.ctxtShutdown(transformCtxt(_obj=ctxt), URI, data)
  71.  
  72.     def styleInit(self, style, URI):
  73.         """Callback function when used in a newly compiled stylesheet,
  74.        the return value is passed in subsequent calls"""
  75.     pass
  76.  
  77.     def styleShutdown(self, style, URI, data):
  78.         """Callback function when a stylesheet using it is destroyed"""
  79.     pass
  80.  
  81.     def ctxtInit(self, ctxt, URI):
  82.         """Callback function when used in a new transformation process,
  83.        the return value is passed in subsequent calls"""
  84.     pass
  85.  
  86.     def ctxtShutdown(self, ctxt, URI, data):
  87.         """Callback function when a transformation using it finishes"""
  88.     pass
  89.  
  90. def cleanup():
  91.     """Cleanup all libxslt and libxml2 memory allocated"""
  92.     libxsltmod.xsltPythonCleanup()
  93.     libxml2.cleanupParser()
  94.  
  95. #
  96. # Everything below this point is automatically generated
  97. #
  98.  
  99. #
  100. # Functions from module extensions
  101. #
  102.  
  103. def debugDumpExtensions(output):
  104.     """Dumps a list of the registered XSLT extension functions and
  105.        elements"""
  106.     libxsltmod.xsltDebugDumpExtensions(output)
  107.  
  108. def registerTestModule():
  109.     """Registers the test module"""
  110.     libxsltmod.xsltRegisterTestModule()
  111.  
  112. def unregisterExtModule(URI):
  113.     """Unregister an XSLT extension module from the library."""
  114.     ret = libxsltmod.xsltUnregisterExtModule(URI)
  115.     return ret
  116.  
  117. def unregisterExtModuleElement(name, URI):
  118.     """Unregisters an extension module element"""
  119.     ret = libxsltmod.xsltUnregisterExtModuleElement(name, URI)
  120.     return ret
  121.  
  122. def unregisterExtModuleFunction(name, URI):
  123.     """Unregisters an extension module function"""
  124.     ret = libxsltmod.xsltUnregisterExtModuleFunction(name, URI)
  125.     return ret
  126.  
  127. def unregisterExtModuleTopLevel(name, URI):
  128.     """Unregisters an extension module top-level element"""
  129.     ret = libxsltmod.xsltUnregisterExtModuleTopLevel(name, URI)
  130.     return ret
  131.  
  132. #
  133. # Functions from module extra
  134. #
  135.  
  136. def registerAllExtras():
  137.     """Registers the built-in extensions"""
  138.     libxsltmod.xsltRegisterAllExtras()
  139.  
  140. #
  141. # Functions from module python
  142. #
  143.  
  144. def pythonCleanup():
  145.     """Cleanup just libxslt (not libxml2) memory allocated"""
  146.     libxsltmod.xsltPythonCleanup()
  147.  
  148. def registerErrorHandler(f, ctx):
  149.     """Register a Python written function to for error reporting.
  150.        The function is called back as f(ctx, error)."""
  151.     ret = libxsltmod.xsltRegisterErrorHandler(f, ctx)
  152.     return ret
  153.  
  154. def registerExtModuleElement(name, URI, precompile, transform):
  155.     """Register a Python written element to the XSLT engine"""
  156.     ret = libxsltmod.xsltRegisterExtModuleElement(name, URI, precompile, transform)
  157.     return ret
  158.  
  159. def registerExtModuleFunction(name, URI, f):
  160.     """Register a Python written function to the XSLT engine"""
  161.     ret = libxsltmod.xsltRegisterExtModuleFunction(name, URI, f)
  162.     return ret
  163.  
  164. def registerExtensionClass(URI, c):
  165.     """Register a Python written extension class to the XSLT engine"""
  166.     ret = libxsltmod.xsltRegisterExtensionClass(URI, c)
  167.     return ret
  168.  
  169. #
  170. # Functions from module xslt
  171. #
  172.  
  173. def cleanupGlobals():
  174.     """Unregister all global variables set up by the XSLT library"""
  175.     libxsltmod.xsltCleanupGlobals()
  176.  
  177. #
  178. # Functions from module xsltInternals
  179. #
  180.  
  181. def isBlank(str):
  182.     """Check if a string is ignorable"""
  183.     ret = libxsltmod.xsltIsBlank(str)
  184.     return ret
  185.  
  186. def loadStylesheetPI(doc):
  187.     """This function tries to locate the stylesheet PI in the
  188.        given document If found, and if contained within the
  189.        document, it will extract that subtree to build the
  190.        stylesheet to process @doc (doc itself will be modified).
  191.        If found but referencing an external document it will
  192.        attempt to load it and generate a stylesheet from it. In
  193.        both cases, the resulting stylesheet and the document need
  194.        to be freed once the transformation is done."""
  195.     if doc == None: doc__o = None
  196.     else: doc__o = doc._o
  197.     ret = libxsltmod.xsltLoadStylesheetPI(doc__o)
  198.     if ret == None: return None
  199.     return stylesheet(_obj=ret)
  200.  
  201. def newStylesheet():
  202.     """Create a new XSLT Stylesheet"""
  203.     ret = libxsltmod.xsltNewStylesheet()
  204.     if ret == None: return None
  205.     return stylesheet(_obj=ret)
  206.  
  207. def parseStylesheetDoc(doc):
  208.     """parse an XSLT stylesheet building the associated structures"""
  209.     if doc == None: doc__o = None
  210.     else: doc__o = doc._o
  211.     ret = libxsltmod.xsltParseStylesheetDoc(doc__o)
  212.     if ret == None: return None
  213.     return stylesheet(_obj=ret)
  214.  
  215. def parseStylesheetFile(filename):
  216.     """Load and parse an XSLT stylesheet"""
  217.     ret = libxsltmod.xsltParseStylesheetFile(filename)
  218.     if ret == None: return None
  219.     return stylesheet(_obj=ret)
  220.  
  221. #
  222. # Functions from module xsltutils
  223. #
  224.  
  225. def calibrateAdjust(delta):
  226.     """Used for to correct the calibration for xsltTimestamp()"""
  227.     libxsltmod.xsltCalibrateAdjust(delta)
  228.  
  229. def debuggerStatus():
  230.     """Get xslDebugStatus."""
  231.     ret = libxsltmod.xsltGetDebuggerStatus()
  232.     return ret
  233.  
  234. def nsProp(node, name, nameSpace):
  235.     """Similar to xmlGetNsProp() but with a slightly different
  236.        semantic  Search and get the value of an attribute
  237.        associated to a node This attribute has to be anchored in
  238.        the namespace specified, or has no namespace and the
  239.        element is in that namespace.  This does the entity
  240.        substitution. This function looks in DTD attribute
  241.        declaration for #FIXED or default declaration values
  242.        unless DTD use has been turned off."""
  243.     if node == None: node__o = None
  244.     else: node__o = node._o
  245.     ret = libxsltmod.xsltGetNsProp(node__o, name, nameSpace)
  246.     return ret
  247.  
  248. def setDebuggerStatus(value):
  249.     """This function sets the value of xslDebugStatus."""
  250.     libxsltmod.xsltSetDebuggerStatus(value)
  251.  
  252. def timestamp():
  253.     """Used for gathering profiling data"""
  254.     ret = libxsltmod.xsltTimestamp()
  255.     return ret
  256.  
  257. def xslDropCall():
  258.     """Drop the topmost item off the call stack"""
  259.     libxsltmod.xslDropCall()
  260.  
  261. class xpathParserContext(libxml2.xpathParserContext):
  262.     def __init__(self, _obj=None):
  263.         self._o = None
  264.         libxml2.xpathParserContext.__init__(self, _obj=_obj)
  265.  
  266.     # accessors for xpathParserContext
  267.     def context(self):
  268.         """Get the xpathContext from an xpathParserContext"""
  269.         ret = libxsltmod.xsltXPathParserGetContext(self._o)
  270.         if ret == None: return None
  271.         return xpathContext(_obj=ret)
  272.  
  273.     #
  274.     # xpathParserContext functions from module extra
  275.     #
  276.  
  277.     def functionNodeSet(self, nargs):
  278.         """Implement the node-set() XSLT function node-set
  279.            node-set(result-tree)  This function is available in
  280.            libxslt, saxon or xt namespace."""
  281.         libxsltmod.xsltFunctionNodeSet(self._o, nargs)
  282.  
  283.     #
  284.     # xpathParserContext functions from module functions
  285.     #
  286.  
  287.     def documentFunction(self, nargs):
  288.         """Implement the document() XSLT function node-set
  289.            document(object, node-set?)"""
  290.         libxsltmod.xsltDocumentFunction(self._o, nargs)
  291.  
  292.     def elementAvailableFunction(self, nargs):
  293.         """Implement the element-available() XSLT function boolean
  294.            element-available(string)"""
  295.         libxsltmod.xsltElementAvailableFunction(self._o, nargs)
  296.  
  297.     def formatNumberFunction(self, nargs):
  298.         """Implement the format-number() XSLT function string
  299.            format-number(number, string, string?)"""
  300.         libxsltmod.xsltFormatNumberFunction(self._o, nargs)
  301.  
  302.     def functionAvailableFunction(self, nargs):
  303.         """Implement the function-available() XSLT function boolean
  304.            function-available(string)"""
  305.         libxsltmod.xsltFunctionAvailableFunction(self._o, nargs)
  306.  
  307.     def generateIdFunction(self, nargs):
  308.         """Implement the generate-id() XSLT function string
  309.            generate-id(node-set?)"""
  310.         libxsltmod.xsltGenerateIdFunction(self._o, nargs)
  311.  
  312.     def keyFunction(self, nargs):
  313.         """Implement the key() XSLT function node-set key(string,
  314.            object)"""
  315.         libxsltmod.xsltKeyFunction(self._o, nargs)
  316.  
  317.     def systemPropertyFunction(self, nargs):
  318.         """Implement the system-property() XSLT function object
  319.            system-property(string)"""
  320.         libxsltmod.xsltSystemPropertyFunction(self._o, nargs)
  321.  
  322.     def unparsedEntityURIFunction(self, nargs):
  323.         """Implement the unparsed-entity-uri() XSLT function string
  324.            unparsed-entity-uri(string)"""
  325.         libxsltmod.xsltUnparsedEntityURIFunction(self._o, nargs)
  326.  
  327. class xpathContext(libxml2.xpathContext):
  328.     def __init__(self, _obj=None):
  329.         self._o = None
  330.         libxml2.xpathContext.__init__(self, _obj=_obj)
  331.  
  332.     def __del__(self):
  333.         pass
  334.     # accessors for xpathContext
  335.     def transformContext(self):
  336.         """Get the transformation context from an xpathContext"""
  337.         ret = libxsltmod.xsltXPathGetTransformContext(self._o)
  338.         if ret == None: return None
  339.         return transformCtxt(_obj=ret)
  340.  
  341.     #
  342.     # xpathContext functions from module functions
  343.     #
  344.  
  345.     def registerAllFunctions(self):
  346.         """Registers all default XSLT functions in this context"""
  347.         libxsltmod.xsltRegisterAllFunctions(self._o)
  348.  
  349. class transformCtxt:
  350.     def __init__(self, _obj=None):
  351.         if _obj != None:self._o = _obj;return
  352.         self._o = None
  353.  
  354.     # accessors for transformCtxt
  355.     def context(self):
  356.         """Get the XPath context of a transformation"""
  357.         ret = libxsltmod.xsltTransformGetContext(self._o)
  358.         if ret == None: return None
  359.         return xpathContext(_obj=ret)
  360.  
  361.     def current(self):
  362.         """Get the current() node of a transformation"""
  363.         ret = libxsltmod.xsltTransformGetCurrent(self._o)
  364.         if ret == None: return None
  365.         return libxml2.xmlNode(_obj=ret)
  366.  
  367.     def insertNode(self):
  368.         """Get the insertion node in the output document"""
  369.         ret = libxsltmod.xsltTransformGetInsertNode(self._o)
  370.         if ret == None: return None
  371.         return libxml2.xmlNode(_obj=ret)
  372.  
  373.     def instruction(self):
  374.         """Get the instruction node in the stylesheet"""
  375.         ret = libxsltmod.xsltTransformGetInstruction(self._o)
  376.         if ret == None: return None
  377.         return libxml2.xmlNode(_obj=ret)
  378.  
  379.     def mode(self):
  380.         """Get the mode of a transformation"""
  381.         ret = libxsltmod.xsltTransformGetMode(self._o)
  382.         return ret
  383.  
  384.     def modeURI(self):
  385.         """Get the mode URI of a transformation"""
  386.         ret = libxsltmod.xsltTransformGetModeURI(self._o)
  387.         return ret
  388.  
  389.     def outputDoc(self):
  390.         """Get the output document of a transformation"""
  391.         ret = libxsltmod.xsltTransformGetOutputDoc(self._o)
  392.         if ret == None: return None
  393.         return libxml2.xmlDoc(_obj=ret)
  394.  
  395.     def outputURI(self):
  396.         """Get the output URI of a transformation if known"""
  397.         ret = libxsltmod.xsltTransformGetOutputURI(self._o)
  398.         return ret
  399.  
  400.     def style(self):
  401.         """Get the stylesheet from a transformation"""
  402.         ret = libxsltmod.xsltTransformGetStyle(self._o)
  403.         if ret == None: return None
  404.         return stylesheet(_obj=ret)
  405.  
  406.     #
  407.     # transformCtxt functions from module attributes
  408.     #
  409.  
  410.     def applyAttributeSet(self, node, inst, attributes):
  411.         """Apply the xsl:use-attribute-sets"""
  412.         if node == None: node__o = None
  413.         else: node__o = node._o
  414.         if inst == None: inst__o = None
  415.         else: inst__o = inst._o
  416.         libxsltmod.xsltApplyAttributeSet(self._o, node__o, inst__o, attributes)
  417.  
  418.     #
  419.     # transformCtxt functions from module documents
  420.     #
  421.  
  422.     def freeDocuments(self):
  423.         """Free up all the space used by the loaded documents"""
  424.         libxsltmod.xsltFreeDocuments(self._o)
  425.  
  426.     #
  427.     # transformCtxt functions from module extensions
  428.     #
  429.  
  430.     def freeCtxtExts(self):
  431.         """Free the XSLT extension data"""
  432.         libxsltmod.xsltFreeCtxtExts(self._o)
  433.  
  434.     def initCtxtExts(self):
  435.         """Initialize the set of modules with registered stylesheet
  436.            data"""
  437.         ret = libxsltmod.xsltInitCtxtExts(self._o)
  438.         return ret
  439.  
  440.     def shutdownCtxtExts(self):
  441.         """Shutdown the set of modules loaded"""
  442.         libxsltmod.xsltShutdownCtxtExts(self._o)
  443.  
  444.     #
  445.     # transformCtxt functions from module extra
  446.     #
  447.  
  448.     def debug(self, node, inst, comp):
  449.         """Process an debug node"""
  450.         if node == None: node__o = None
  451.         else: node__o = node._o
  452.         if inst == None: inst__o = None
  453.         else: inst__o = inst._o
  454.         libxsltmod.xsltDebug(self._o, node__o, inst__o, comp)
  455.  
  456.     def registerExtras(self):
  457.         """Registers the built-in extensions. This function is
  458.            deprecated, use xsltRegisterAllExtras instead."""
  459.         libxsltmod.xsltRegisterExtras(self._o)
  460.  
  461.     #
  462.     # transformCtxt functions from module imports
  463.     #
  464.  
  465.     def findElemSpaceHandling(self, node):
  466.         """Find strip-space or preserve-space informations for an
  467.            element respect the import precedence or the wildcards"""
  468.         if node == None: node__o = None
  469.         else: node__o = node._o
  470.         ret = libxsltmod.xsltFindElemSpaceHandling(self._o, node__o)
  471.         return ret
  472.  
  473.     def needElemSpaceHandling(self):
  474.         """Checks whether that stylesheet requires white-space
  475.            stripping"""
  476.         ret = libxsltmod.xsltNeedElemSpaceHandling(self._o)
  477.         return ret
  478.  
  479.     #
  480.     # transformCtxt functions from module namespaces
  481.     #
  482.  
  483.     def copyNamespace(self, node, cur):
  484.         """Do a copy of an namespace node. If @node is non-None the
  485.            new namespaces are added automatically. This handles
  486.            namespaces aliases"""
  487.         if node == None: node__o = None
  488.         else: node__o = node._o
  489.         if cur == None: cur__o = None
  490.         else: cur__o = cur._o
  491.         ret = libxsltmod.xsltCopyNamespace(self._o, node__o, cur__o)
  492.         if ret == None: return None
  493.         return libxml2.xmlNs(_obj=ret)
  494.  
  495.     def copyNamespaceList(self, node, cur):
  496.         """Do a copy of an namespace list. If @node is non-None the
  497.            new namespaces are added automatically. This handles
  498.            namespaces aliases"""
  499.         if node == None: node__o = None
  500.         else: node__o = node._o
  501.         if cur == None: cur__o = None
  502.         else: cur__o = cur._o
  503.         ret = libxsltmod.xsltCopyNamespaceList(self._o, node__o, cur__o)
  504.         if ret == None: return None
  505.         return libxml2.xmlNs(_obj=ret)
  506.  
  507.     def namespace(self, cur, ns, out):
  508.         """Find the right namespace value for this prefix, if needed
  509.            create and add a new namespace decalaration on the node
  510.            Handle namespace aliases"""
  511.         if cur == None: cur__o = None
  512.         else: cur__o = cur._o
  513.         if ns == None: ns__o = None
  514.         else: ns__o = ns._o
  515.         if out == None: out__o = None
  516.         else: out__o = out._o
  517.         ret = libxsltmod.xsltGetNamespace(self._o, cur__o, ns__o, out__o)
  518.         if ret == None: return None
  519.         return libxml2.xmlNs(_obj=ret)
  520.  
  521.     def plainNamespace(self, cur, ns, out):
  522.         """Find the right namespace value for this prefix, if needed
  523.            create and add a new namespace decalaration on the node
  524.            Handle namespace aliases and make sure the prefix is not
  525.            None, this is needed for attributes."""
  526.         if cur == None: cur__o = None
  527.         else: cur__o = cur._o
  528.         if ns == None: ns__o = None
  529.         else: ns__o = ns._o
  530.         if out == None: out__o = None
  531.         else: out__o = out._o
  532.         ret = libxsltmod.xsltGetPlainNamespace(self._o, cur__o, ns__o, out__o)
  533.         if ret == None: return None
  534.         return libxml2.xmlNs(_obj=ret)
  535.  
  536.     def specialNamespace(self, cur, URI, prefix, out):
  537.         """Find the right namespace value for this URI, if needed
  538.            create and add a new namespace decalaration on the node"""
  539.         if cur == None: cur__o = None
  540.         else: cur__o = cur._o
  541.         if out == None: out__o = None
  542.         else: out__o = out._o
  543.         ret = libxsltmod.xsltGetSpecialNamespace(self._o, cur__o, URI, prefix, out__o)
  544.         if ret == None: return None
  545.         return libxml2.xmlNs(_obj=ret)
  546.  
  547.     #
  548.     # transformCtxt functions from module templates
  549.     #
  550.  
  551.     def attrListTemplateProcess(self, target, cur):
  552.         """Do a copy of an attribute list with attribute template
  553.            processing"""
  554.         if target == None: target__o = None
  555.         else: target__o = target._o
  556.         if cur == None: cur__o = None
  557.         else: cur__o = cur._o
  558.         ret = libxsltmod.xsltAttrListTemplateProcess(self._o, target__o, cur__o)
  559.         if ret == None: return None
  560.         return libxml2.xmlAttr(_obj=ret)
  561.  
  562.     def attrTemplateProcess(self, target, cur):
  563.         """Process the given attribute and return the new processed
  564.            copy."""
  565.         if target == None: target__o = None
  566.         else: target__o = target._o
  567.         if cur == None: cur__o = None
  568.         else: cur__o = cur._o
  569.         ret = libxsltmod.xsltAttrTemplateProcess(self._o, target__o, cur__o)
  570.         if ret == None: return None
  571.         return libxml2.xmlAttr(_obj=ret)
  572.  
  573.     def attrTemplateValueProcess(self, str):
  574.         """Process the given node and return the new string value."""
  575.         ret = libxsltmod.xsltAttrTemplateValueProcess(self._o, str)
  576.         return ret
  577.  
  578.     def attrTemplateValueProcessNode(self, str, node):
  579.         """Process the given string, allowing to pass a namespace
  580.            mapping context and return the new string value."""
  581.         if node == None: node__o = None
  582.         else: node__o = node._o
  583.         ret = libxsltmod.xsltAttrTemplateValueProcessNode(self._o, str, node__o)
  584.         return ret
  585.  
  586.     def evalAttrValueTemplate(self, node, name, ns):
  587.         """Evaluate a attribute value template, i.e. the attribute
  588.            value can contain expressions contained in curly braces
  589.            ({}) and those are substituted by they computed value."""
  590.         if node == None: node__o = None
  591.         else: node__o = node._o
  592.         ret = libxsltmod.xsltEvalAttrValueTemplate(self._o, node__o, name, ns)
  593.         return ret
  594.  
  595.     def evalTemplateString(self, node, parent):
  596.         """Evaluate a template string value, i.e. the parent list is
  597.            interpreter as template content and the resulting tree
  598.            string value is returned This is needed for example by
  599.            xsl:comment and xsl:processing-instruction"""
  600.         if node == None: node__o = None
  601.         else: node__o = node._o
  602.         if parent == None: parent__o = None
  603.         else: parent__o = parent._o
  604.         ret = libxsltmod.xsltEvalTemplateString(self._o, node__o, parent__o)
  605.         return ret
  606.  
  607.     #
  608.     # transformCtxt functions from module variables
  609.     #
  610.  
  611.     def evalGlobalVariables(self):
  612.         """Evaluate the global variables of a stylesheet. This need to
  613.            be done on parsed stylesheets before starting to apply
  614.            transformations"""
  615.         ret = libxsltmod.xsltEvalGlobalVariables(self._o)
  616.         return ret
  617.  
  618.     def evalOneUserParam(self, name, value):
  619.         """This is normally called from xsltEvalUserParams to process
  620.            a single parameter from a list of parameters.  The @value
  621.            is evaluated as an XPath expression and the result is
  622.            stored in the context's global variable/parameter hash
  623.            table.  To have a parameter treated literally (not as an
  624.            XPath expression) use xsltQuoteUserParams (or
  625.            xsltQuoteOneUserParam).  For more details see description
  626.            of xsltProcessOneUserParamInternal."""
  627.         ret = libxsltmod.xsltEvalOneUserParam(self._o, name, value)
  628.         return ret
  629.  
  630.     def freeGlobalVariables(self):
  631.         """Free up the data associated to the global variables its
  632.            value."""
  633.         libxsltmod.xsltFreeGlobalVariables(self._o)
  634.  
  635.     def parseStylesheetParam(self, cur):
  636.         """parse an XSLT transformation param declaration and record
  637.            its value."""
  638.         if cur == None: cur__o = None
  639.         else: cur__o = cur._o
  640.         libxsltmod.xsltParseStylesheetParam(self._o, cur__o)
  641.  
  642.     def parseStylesheetVariable(self, cur):
  643.         """parse an XSLT transformation variable declaration and
  644.            record its value."""
  645.         if cur == None: cur__o = None
  646.         else: cur__o = cur._o
  647.         libxsltmod.xsltParseStylesheetVariable(self._o, cur__o)
  648.  
  649.     def quoteOneUserParam(self, name, value):
  650.         """This is normally called from xsltQuoteUserParams to process
  651.            a single parameter from a list of parameters.  The @value
  652.            is stored in the context's global variable/parameter hash
  653.            table."""
  654.         ret = libxsltmod.xsltQuoteOneUserParam(self._o, name, value)
  655.         return ret
  656.  
  657.     def variableLookup(self, name, ns_uri):
  658.         """Search in the Variable array of the context for the given
  659.            variable value."""
  660.         ret = libxsltmod.xsltVariableLookup(self._o, name, ns_uri)
  661.         if ret == None: return None
  662.         return libxml2.xpathObjectRet(ret)
  663.  
  664.     #
  665.     # transformCtxt functions from module xsltInternals
  666.     #
  667.  
  668.     def allocateExtraCtxt(self):
  669.         """Allocate an extra runtime information slot at run-time and
  670.            return its number This make sure there is a slot ready in
  671.            the transformation context"""
  672.         ret = libxsltmod.xsltAllocateExtraCtxt(self._o)
  673.         return ret
  674.  
  675.     def createRVT(self):
  676.         """Create a result value tree"""
  677.         ret = libxsltmod.xsltCreateRVT(self._o)
  678.         if ret == None: return None
  679.         return libxml2.xmlDoc(_obj=ret)
  680.  
  681.     def freeRVTs(self):
  682.         """Free all the registered result value tree of the
  683.            transformation"""
  684.         libxsltmod.xsltFreeRVTs(self._o)
  685.  
  686.     def registerPersistRVT(self, RVT):
  687.         """Register the result value tree for destruction at the end
  688.            of the processing"""
  689.         if RVT == None: RVT__o = None
  690.         else: RVT__o = RVT._o
  691.         ret = libxsltmod.xsltRegisterPersistRVT(self._o, RVT__o)
  692.         return ret
  693.  
  694.     def registerTmpRVT(self, RVT):
  695.         """Register the result value tree for destruction at the end
  696.            of the context"""
  697.         if RVT == None: RVT__o = None
  698.         else: RVT__o = RVT._o
  699.         ret = libxsltmod.xsltRegisterTmpRVT(self._o, RVT__o)
  700.         return ret
  701.  
  702.     #
  703.     # transformCtxt functions from module xsltutils
  704.     #
  705.  
  706.     def message(self, node, inst):
  707.         """Process and xsl:message construct"""
  708.         if node == None: node__o = None
  709.         else: node__o = node._o
  710.         if inst == None: inst__o = None
  711.         else: inst__o = inst._o
  712.         libxsltmod.xsltMessage(self._o, node__o, inst__o)
  713.  
  714.     def printErrorContext(self, style, node):
  715.         """Display the context of an error."""
  716.         if style == None: style__o = None
  717.         else: style__o = style._o
  718.         if node == None: node__o = None
  719.         else: node__o = node._o
  720.         libxsltmod.xsltPrintErrorContext(self._o, style__o, node__o)
  721.  
  722.     def profileInformation(self):
  723.         """This function should be called after the transformation
  724.            completed to extract template processing profiling
  725.            informations if availble. The informations are returned as
  726.            an XML document tree like <?xml version="1.0"?> <profile>
  727.            <template rank="1" match="*" name="" mode="" calls="6"
  728.            time="48" average="8"/> <template rank="2"
  729.            match="item2|item3" name="" mode="" calls="10" time="30"
  730.            average="3"/> <template rank="3" match="item1" name=""
  731.            mode="" calls="5" time="17" average="3"/> </profile> The
  732.            caller will need to free up the returned tree with
  733.            xmlFreeDoc()"""
  734.         ret = libxsltmod.xsltGetProfileInformation(self._o)
  735.         if ret == None: return None
  736.         return libxml2.xmlDoc(_obj=ret)
  737.  
  738.     def saveProfiling(self, output):
  739.         """Save the profiling informations on @output"""
  740.         libxsltmod.xsltSaveProfiling(self._o, output)
  741.  
  742.     def setCtxtParseOptions(self, options):
  743.         """Change the default parser option passed by the XSLT engine
  744.            to the parser when using document() loading."""
  745.         ret = libxsltmod.xsltSetCtxtParseOptions(self._o, options)
  746.         return ret
  747.  
  748. class stylesheet:
  749.     def __init__(self, _obj=None):
  750.         if _obj != None:self._o = _obj;return
  751.         self._o = None
  752.  
  753.     # accessors for stylesheet
  754.     def doc(self):
  755.         """Get the document of a stylesheet"""
  756.         ret = libxsltmod.xsltStylesheetGetDoc(self._o)
  757.         if ret == None: return None
  758.         return libxml2.xmlDoc(_obj=ret)
  759.  
  760.     def doctypePublic(self):
  761.         """Get the output PUBLIC of a stylesheet"""
  762.         ret = libxsltmod.xsltStylesheetGetDoctypePublic(self._o)
  763.         return ret
  764.  
  765.     def doctypeSystem(self):
  766.         """Get the output SYSTEM of a stylesheet"""
  767.         ret = libxsltmod.xsltStylesheetGetDoctypeSystem(self._o)
  768.         return ret
  769.  
  770.     def encoding(self):
  771.         """Get the output encoding of a stylesheet"""
  772.         ret = libxsltmod.xsltStylesheetGetEncoding(self._o)
  773.         return ret
  774.  
  775.     def imports(self):
  776.         """Get the imports of a stylesheet"""
  777.         ret = libxsltmod.xsltStylesheetGetImports(self._o)
  778.         if ret == None: return None
  779.         return stylesheet(_obj=ret)
  780.  
  781.     def method(self):
  782.         """Get the output method of a stylesheet"""
  783.         ret = libxsltmod.xsltStylesheetGetMethod(self._o)
  784.         return ret
  785.  
  786.     def methodURI(self):
  787.         """Get the output method URI of a stylesheet"""
  788.         ret = libxsltmod.xsltStylesheetGetMethodURI(self._o)
  789.         return ret
  790.  
  791.     def next(self):
  792.         """Get the next sibling of a stylesheet"""
  793.         ret = libxsltmod.xsltStylesheetGetNext(self._o)
  794.         if ret == None: return None
  795.         return stylesheet(_obj=ret)
  796.  
  797.     def parent(self):
  798.         """Get the parent of a stylesheet"""
  799.         ret = libxsltmod.xsltStylesheetGetParent(self._o)
  800.         if ret == None: return None
  801.         return stylesheet(_obj=ret)
  802.  
  803.     def version(self):
  804.         """Get the output version of a stylesheet"""
  805.         ret = libxsltmod.xsltStylesheetGetVersion(self._o)
  806.         return ret
  807.  
  808.     #
  809.     # stylesheet functions from module attributes
  810.     #
  811.  
  812.     def freeAttributeSetsHashes(self):
  813.         """Free up the memory used by attribute sets"""
  814.         libxsltmod.xsltFreeAttributeSetsHashes(self._o)
  815.  
  816.     def parseStylesheetAttributeSet(self, cur):
  817.         """parse an XSLT stylesheet attribute-set element"""
  818.         if cur == None: cur__o = None
  819.         else: cur__o = cur._o
  820.         libxsltmod.xsltParseStylesheetAttributeSet(self._o, cur__o)
  821.  
  822.     def resolveStylesheetAttributeSet(self):
  823.         """resolve the references between attribute sets."""
  824.         libxsltmod.xsltResolveStylesheetAttributeSet(self._o)
  825.  
  826.     #
  827.     # stylesheet functions from module documents
  828.     #
  829.  
  830.     def freeStyleDocuments(self):
  831.         """Free up all the space used by the loaded documents"""
  832.         libxsltmod.xsltFreeStyleDocuments(self._o)
  833.  
  834.     #
  835.     # stylesheet functions from module extensions
  836.     #
  837.  
  838.     def checkExtPrefix(self, prefix):
  839.         """Check if the given prefix is one of the declared extensions"""
  840.         ret = libxsltmod.xsltCheckExtPrefix(self._o, prefix)
  841.         return ret
  842.  
  843.     def freeExts(self):
  844.         """Free up the memory used by XSLT extensions in a stylesheet"""
  845.         libxsltmod.xsltFreeExts(self._o)
  846.  
  847.     def registerExtPrefix(self, prefix, URI):
  848.         """Registers an extension namespace"""
  849.         ret = libxsltmod.xsltRegisterExtPrefix(self._o, prefix, URI)
  850.         return ret
  851.  
  852.     def shutdownExts(self):
  853.         """Shutdown the set of modules loaded"""
  854.         libxsltmod.xsltShutdownExts(self._o)
  855.  
  856.     #
  857.     # stylesheet functions from module imports
  858.     #
  859.  
  860.     def nextImport(self):
  861.         """Find the next stylesheet in import precedence."""
  862.         ret = libxsltmod.xsltNextImport(self._o)
  863.         if ret == None: return None
  864.         return stylesheet(_obj=ret)
  865.  
  866.     def parseStylesheetImport(self, cur):
  867.         """parse an XSLT stylesheet import element"""
  868.         if cur == None: cur__o = None
  869.         else: cur__o = cur._o
  870.         ret = libxsltmod.xsltParseStylesheetImport(self._o, cur__o)
  871.         return ret
  872.  
  873.     def parseStylesheetInclude(self, cur):
  874.         """parse an XSLT stylesheet include element"""
  875.         if cur == None: cur__o = None
  876.         else: cur__o = cur._o
  877.         ret = libxsltmod.xsltParseStylesheetInclude(self._o, cur__o)
  878.         return ret
  879.  
  880.     #
  881.     # stylesheet functions from module keys
  882.     #
  883.  
  884.     def addKey(self, name, nameURI, match, use, inst):
  885.         """add a key definition to a stylesheet"""
  886.         if inst == None: inst__o = None
  887.         else: inst__o = inst._o
  888.         ret = libxsltmod.xsltAddKey(self._o, name, nameURI, match, use, inst__o)
  889.         return ret
  890.  
  891.     def freeKeys(self):
  892.         """Free up the memory used by XSLT keys in a stylesheet"""
  893.         libxsltmod.xsltFreeKeys(self._o)
  894.  
  895.     #
  896.     # stylesheet functions from module namespaces
  897.     #
  898.  
  899.     def freeNamespaceAliasHashes(self):
  900.         """Free up the memory used by namespaces aliases"""
  901.         libxsltmod.xsltFreeNamespaceAliasHashes(self._o)
  902.  
  903.     def namespaceAlias(self, node):
  904.         """Read the stylesheet-prefix and result-prefix attributes,
  905.            register them as well as the corresponding namespace."""
  906.         if node == None: node__o = None
  907.         else: node__o = node._o
  908.         libxsltmod.xsltNamespaceAlias(self._o, node__o)
  909.  
  910.     #
  911.     # stylesheet functions from module pattern
  912.     #
  913.  
  914.     def cleanupTemplates(self):
  915.         """Cleanup the state of the templates used by the stylesheet
  916.            and the ones it imports."""
  917.         libxsltmod.xsltCleanupTemplates(self._o)
  918.  
  919.     def freeTemplateHashes(self):
  920.         """Free up the memory used by xsltAddTemplate/xsltGetTemplate
  921.            mechanism"""
  922.         libxsltmod.xsltFreeTemplateHashes(self._o)
  923.  
  924.     #
  925.     # stylesheet functions from module preproc
  926.     #
  927.  
  928.     def freeStylePreComps(self):
  929.         """Free up the memory allocated by all precomputed blocks"""
  930.         libxsltmod.xsltFreeStylePreComps(self._o)
  931.  
  932.     def stylePreCompute(self, inst):
  933.         """Precompute an XSLT stylesheet element"""
  934.         if inst == None: inst__o = None
  935.         else: inst__o = inst._o
  936.         libxsltmod.xsltStylePreCompute(self._o, inst__o)
  937.  
  938.     #
  939.     # stylesheet functions from module python
  940.     #
  941.  
  942.     def applyStylesheet(self, doc, params):
  943.         """Apply the stylesheet to the document"""
  944.         if doc == None: doc__o = None
  945.         else: doc__o = doc._o
  946.         ret = libxsltmod.xsltApplyStylesheet(self._o, doc__o, params)
  947.         if ret == None: return None
  948.         return libxml2.xmlDoc(_obj=ret)
  949.  
  950.     def saveResultToString(self, result):
  951.         """Have the stylesheet serialize the result of a
  952.            transformation to a python string"""
  953.         if result == None: result__o = None
  954.         else: result__o = result._o
  955.         ret = libxsltmod.xsltSaveResultToString(self._o, result__o)
  956.         return ret
  957.  
  958.     #
  959.     # stylesheet functions from module variables
  960.     #
  961.  
  962.     def parseGlobalParam(self, cur):
  963.         """parse an XSLT transformation param declaration and record
  964.            its value."""
  965.         if cur == None: cur__o = None
  966.         else: cur__o = cur._o
  967.         libxsltmod.xsltParseGlobalParam(self._o, cur__o)
  968.  
  969.     def parseGlobalVariable(self, cur):
  970.         """parse an XSLT transformation variable declaration and
  971.            record its value."""
  972.         if cur == None: cur__o = None
  973.         else: cur__o = cur._o
  974.         libxsltmod.xsltParseGlobalVariable(self._o, cur__o)
  975.  
  976.     #
  977.     # stylesheet functions from module xsltInternals
  978.     #
  979.  
  980.     def allocateExtra(self):
  981.         """Allocate an extra runtime information slot statically while
  982.            compiling the stylesheet and return its number"""
  983.         ret = libxsltmod.xsltAllocateExtra(self._o)
  984.         return ret
  985.  
  986.     def compileAttr(self, attr):
  987.         """Precompile an attribute in a stylesheet, basically it
  988.            checks if it is an attrubute value template, and if yes
  989.            establish some structures needed to process it at
  990.            transformation time."""
  991.         if attr == None: attr__o = None
  992.         else: attr__o = attr._o
  993.         libxsltmod.xsltCompileAttr(self._o, attr__o)
  994.  
  995.     def freeStylesheet(self):
  996.         """Free up the memory allocated by @sheet"""
  997.         libxsltmod.xsltFreeStylesheet(self._o)
  998.  
  999.     def parseStylesheetImportedDoc(self, doc):
  1000.         """parse an XSLT stylesheet building the associated structures
  1001.            except the processing not needed for imported documents."""
  1002.         if doc == None: doc__o = None
  1003.         else: doc__o = doc._o
  1004.         ret = libxsltmod.xsltParseStylesheetImportedDoc(doc__o, self._o)
  1005.         if ret == None: return None
  1006.         return stylesheet(_obj=ret)
  1007.  
  1008.     def parseStylesheetOutput(self, cur):
  1009.         """parse an XSLT stylesheet output element and record
  1010.            information related to the stylesheet output"""
  1011.         if cur == None: cur__o = None
  1012.         else: cur__o = cur._o
  1013.         libxsltmod.xsltParseStylesheetOutput(self._o, cur__o)
  1014.  
  1015.     def parseStylesheetProcess(self, doc):
  1016.         """parse an XSLT stylesheet adding the associated structures"""
  1017.         if doc == None: doc__o = None
  1018.         else: doc__o = doc._o
  1019.         ret = libxsltmod.xsltParseStylesheetProcess(self._o, doc__o)
  1020.         if ret == None: return None
  1021.         return stylesheet(_obj=ret)
  1022.  
  1023.     def parseTemplateContent(self, templ):
  1024.         """parse a template content-model Clean-up the template
  1025.            content from unwanted ignorable blank nodes and process
  1026.            xslt:text"""
  1027.         if templ == None: templ__o = None
  1028.         else: templ__o = templ._o
  1029.         libxsltmod.xsltParseTemplateContent(self._o, templ__o)
  1030.  
  1031.     #
  1032.     # stylesheet functions from module xsltutils
  1033.     #
  1034.  
  1035.     def cNsProp(self, node, name, nameSpace):
  1036.         """Similar to xmlGetNsProp() but with a slightly different
  1037.            semantic  Search and get the value of an attribute
  1038.            associated to a node This attribute has to be anchored in
  1039.            the namespace specified, or has no namespace and the
  1040.            element is in that namespace.  This does the entity
  1041.            substitution. This function looks in DTD attribute
  1042.            declaration for #FIXED or default declaration values
  1043.            unless DTD use has been turned off."""
  1044.         if node == None: node__o = None
  1045.         else: node__o = node._o
  1046.         ret = libxsltmod.xsltGetCNsProp(self._o, node__o, name, nameSpace)
  1047.         return ret
  1048.  
  1049.     def printErrorContext(self, ctxt, node):
  1050.         """Display the context of an error."""
  1051.         if ctxt == None: ctxt__o = None
  1052.         else: ctxt__o = ctxt._o
  1053.         if node == None: node__o = None
  1054.         else: node__o = node._o
  1055.         libxsltmod.xsltPrintErrorContext(ctxt__o, self._o, node__o)
  1056.  
  1057.     def saveResultToFd(self, fd, result):
  1058.         """Save the result @result obtained by applying the @style
  1059.            stylesheet to an open file descriptor This does not close
  1060.            the descriptor."""
  1061.         if result == None: result__o = None
  1062.         else: result__o = result._o
  1063.         ret = libxsltmod.xsltSaveResultToFd(fd, result__o, self._o)
  1064.         return ret
  1065.  
  1066.     def saveResultToFile(self, file, result):
  1067.         """Save the result @result obtained by applying the @style
  1068.            stylesheet to an open FILE * I/O. This does not close the
  1069.            FILE @file"""
  1070.         if result == None: result__o = None
  1071.         else: result__o = result._o
  1072.         ret = libxsltmod.xsltSaveResultToFile(file, result__o, self._o)
  1073.         return ret
  1074.  
  1075.     def saveResultToFilename(self, URL, result, compression):
  1076.         """Save the result @result obtained by applying the @style
  1077.            stylesheet to a file or @URL"""
  1078.         if result == None: result__o = None
  1079.         else: result__o = result._o
  1080.         ret = libxsltmod.xsltSaveResultToFilename(URL, result__o, self._o, compression)
  1081.         return ret
  1082.  
  1083. # xsltTransformState
  1084. XSLT_STATE_OK = 0
  1085. XSLT_STATE_ERROR = 1
  1086. XSLT_STATE_STOPPED = 2
  1087.  
  1088. # xsltDebugStatusCodes
  1089. XSLT_DEBUG_NONE = 0
  1090. XSLT_DEBUG_INIT = 1
  1091. XSLT_DEBUG_STEP = 2
  1092. XSLT_DEBUG_STEPOUT = 3
  1093. XSLT_DEBUG_NEXT = 4
  1094. XSLT_DEBUG_STOP = 5
  1095. XSLT_DEBUG_CONT = 6
  1096. XSLT_DEBUG_RUN = 7
  1097. XSLT_DEBUG_RUN_RESTART = 8
  1098. XSLT_DEBUG_QUIT = 9
  1099.  
  1100. # xsltOutputType
  1101. XSLT_OUTPUT_XML = 0
  1102. XSLT_OUTPUT_HTML = 1
  1103. XSLT_OUTPUT_TEXT = 2
  1104.  
  1105. # xsltStyleType
  1106. XSLT_FUNC_COPY = 1
  1107. XSLT_FUNC_SORT = 2
  1108. XSLT_FUNC_TEXT = 3
  1109. XSLT_FUNC_ELEMENT = 4
  1110. XSLT_FUNC_ATTRIBUTE = 5
  1111. XSLT_FUNC_COMMENT = 6
  1112. XSLT_FUNC_PI = 7
  1113. XSLT_FUNC_COPYOF = 8
  1114. XSLT_FUNC_VALUEOF = 9
  1115. XSLT_FUNC_NUMBER = 10
  1116. XSLT_FUNC_APPLYIMPORTS = 11
  1117. XSLT_FUNC_CALLTEMPLATE = 12
  1118. XSLT_FUNC_APPLYTEMPLATES = 13
  1119. XSLT_FUNC_CHOOSE = 14
  1120. XSLT_FUNC_IF = 15
  1121. XSLT_FUNC_FOREACH = 16
  1122. XSLT_FUNC_DOCUMENT = 17
  1123. XSLT_FUNC_WITHPARAM = 18
  1124. XSLT_FUNC_PARAM = 19
  1125. XSLT_FUNC_VARIABLE = 20
  1126. XSLT_FUNC_WHEN = 21
  1127. XSLT_FUNC_EXTENSION = 22
  1128.  
  1129. # xsltLoadType
  1130. XSLT_LOAD_START = 0
  1131. XSLT_LOAD_STYLESHEET = 1
  1132. XSLT_LOAD_DOCUMENT = 2
  1133.  
  1134. # xsltSecurityOption
  1135. XSLT_SECPREF_READ_FILE = 1
  1136. XSLT_SECPREF_WRITE_FILE = 2
  1137. XSLT_SECPREF_CREATE_DIRECTORY = 3
  1138. XSLT_SECPREF_READ_NETWORK = 4
  1139. XSLT_SECPREF_WRITE_NETWORK = 5
  1140.  
  1141. # xsltDebugTraceCodes
  1142. XSLT_TRACE_ALL = -1
  1143. XSLT_TRACE_NONE = 0
  1144. XSLT_TRACE_COPY_TEXT = 1
  1145. XSLT_TRACE_PROCESS_NODE = 2
  1146. XSLT_TRACE_APPLY_TEMPLATE = 4
  1147. XSLT_TRACE_COPY = 8
  1148. XSLT_TRACE_COMMENT = 16
  1149. XSLT_TRACE_PI = 32
  1150. XSLT_TRACE_COPY_OF = 64
  1151. XSLT_TRACE_VALUE_OF = 128
  1152. XSLT_TRACE_CALL_TEMPLATE = 256
  1153. XSLT_TRACE_APPLY_TEMPLATES = 512
  1154. XSLT_TRACE_CHOOSE = 1024
  1155. XSLT_TRACE_IF = 2048
  1156. XSLT_TRACE_FOR_EACH = 4096
  1157. XSLT_TRACE_STRIP_SPACES = 8192
  1158. XSLT_TRACE_TEMPLATES = 16384
  1159. XSLT_TRACE_KEYS = 32768
  1160. XSLT_TRACE_VARIABLES = 65536
  1161.  
  1162.