;ò lh†>c@s‹dZddd!Zddd!Zddd!ZdkZdkZdklZdkZd k l Z d Z d Z d Z d fd„ƒYZ dS(s: $RCSfile: LibXsltProcessor.py,v $ This class encapsulates an XSLT Processor for use by ZopeXMLMethods. This is the GNOME libxslt version, including support for XSLT parameters. It does not yet include support for URN resolution. Author: Craeg Strong Release: 1.0 s $Name: $iiþÿÿÿs$Date: 2003/03/30 03:45:47 $s$Revision: 1.17 $i N(saq_get(sIXSLTProcessors URNnamespacess XSLparameterss XMLcatalogsLibXsltProcessorcBsqtZdZeZdZd„Zd„Zeed„Z d„Z eeed„Z d„Z d„Z d „ZRS( sÛ This class encapsulates an XSLT Processor for use by ZopeXMLMethods. This is the GNOME libxslt version, including support for XSLT parameters. It does not yet include support for URN resolution. slibxslt 1.0.27cCsMd|_ti|idƒti|idƒtidƒtidƒdS(s-Initialize a new instance of LibXsltProcessorisiN(sselfs debugLevelslibxml2sregisterErrorHandlers errorHandlerslibxsltslineNumbersDefaultssubstituteEntitiesDefault(sself((sN/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/LibXsltProcessor.pys__init__5s   cCs ||_dS(s‹ Set debug level from 0 to 3. 0 = silent 3 = extra verbose Debug messages go to Zope server log. N(slevelsselfs debugLevel(sselfslevel((sN/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/LibXsltProcessor.pys setDebugLevelCsc CsÎt}|tj o|i|ƒ}n|idjo dG|GHn|idjodGH|GHdGH|GHny%|i|||||||ƒ} Wn3t j o'}tiit|ƒdƒdSnX| SdS(sE Transforms the passed in XML into the required output (usually HTML) using the passed in XSLT. Both the XML and XSLT strings should be well-formed. Returns the output as a string. transformObject and REQUEST params may be used to acquire Zope content such as XSLT parameters and URN namespaces, if required. Catches any exceptions thrown by transformGuts and sends the error output to stderr, returns empty string to the caller. The idea is that web site users will at worst see an empty page. isparams:s xsltContents:s xmlContents:s sN(sNonestopLevelParamsstransformObjectsselfsgetXSLParameterss debugLevels xsltContentss xmlContentss transformGutssxmlURLsxsltURLsREQUESTsresults Exceptionsessyssstderrswritesstr( sselfs xmlContentssxmlURLs xsltContentssxsltURLstransformObjectsREQUESTsestopLevelParamssresult((sN/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/LibXsltProcessor.pys transformNs$    cCsd|||<|SdS(sà This is a convenience function for adding parameters in the correct format to the parameter map to be used for the 'params' parameter in transformGuts. s'%s'N(svaluesparamMapsname(sselfsparamMapsnamesvalue((sN/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/LibXsltProcessor.pysaddParamtscCs y ti|ƒ}|i|ƒWn:tij o+}d|t|ƒf} t | ƒ‚nXt i |ƒ} y ti|ƒ} | i|ƒWn4tij o%}dt|ƒ} t | ƒ‚nX| i| |ƒ} | i| ƒ} | iƒ| iƒ| iƒ| SdS(sw Actually performs the transformation. Throws an Exception if there are any errors. s$XML parse error for XSLT file %s: %ss$XML parse error for XML document: %sN(slibxml2sparseDocs xsltContentssstyleDocssetBasesxsltURLs parserErrorsesstrsmessages ExceptionslibxsltsparseStylesheetDocsstyles xmlContentssxmlDocsxmlURLsapplyStylesheetsparamss resultDocssaveResultToStringsresultsfreeStylesheetsfreeDoc(sselfs xmlContentssxmlURLs xsltContentssxsltURLstransformObjectsparamssREQUESTsesstyles resultDocsresultsmessagesxmlDocsstyleDoc((sN/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/LibXsltProcessor.pys transformGutss(   cCst|ƒ‚dS(s™ The default error handler for libxml2 and libxslt prints out messages to stderr. Throw an exception instead. N(s Exceptionserror(sselfsctxserror((sN/mnt/gmirror/ports/www/zope-xmlmethods/work/ZopeXMLMethods/LibXsltProcessor.pys errorHandlerÒscCst|ttƒ}h}|tj oRxO|D]C}t||tƒ}t|ƒo|||