예제 #1
0
def transform(doc, styleSheet, params=None):
    # Redirect libxml error messages
    libxml2.registerErrorHandler(callback, None)
    libxslt.registerErrorHandler(callback, None)

    # Transforms doc (XML data) with style (XSLT stylesheet file name)
    try:
        styledoc = libxml2.parseFile(styleSheet)
    except libxml2.parserError, e:
        raise "Could not parse %s" % styleSheet, e
예제 #2
0
def xmlToRoadmap(filePath):
    libxml2.registerErrorHandler(lambda ctx,str: None, None)
    libxslt.registerErrorHandler(lambda ctx,str: None, None)
    pmlStyleDoc=libxml2.parseFile(settings.PML_PATH + "/xpml/pmldoc.xsl")
    style = libxslt.parseStylesheetDoc(pmlStyleDoc)
    try:
        doc = libxml2.parseFile(filePath)
        result = style.applyStylesheet(doc, None)
        return style.saveResultToString(result)
    except (libxml2.parserError, TypeError):
        return None
예제 #3
0
def xmlToPml(filePath):
    #Redirect XML errors away from stdout so that it doesn't cause a
    #mod_wsgi exception.
    libxml2.registerErrorHandler(lambda ctx,str: None, None)
    libxslt.registerErrorHandler(lambda ctx,str: None, None)
    pmlStyleDoc=libxml2.parseFile(settings.PML_PATH + "/xpml/xpml.xsl")
    style = libxslt.parseStylesheetDoc(pmlStyleDoc)
    try:
        doc = libxml2.parseFile(filePath)
        result = style.applyStylesheet(doc, None)
        return style.saveResultToString(result)
    except (libxml2.parserError, TypeError):
        return None
예제 #4
0
def registerErrorHandler(f, ctx):
    """Register a Python written function to for error reporting.
       The function is called back as f(ctx, error). """
    import sys
    if 'libxslt' not in sys.modules:
        # normal behaviour when libxslt is not imported
        ret = libxml2mod.xmlRegisterErrorHandler(f,ctx)
    else:
        # when libxslt is already imported, one must
        # use libxst's error handler instead
        import libxslt
        ret = libxslt.registerErrorHandler(f,ctx)
    return ret
예제 #5
0
def registerErrorHandler(f, ctx):
    """Register a Python written function to for error reporting.
       The function is called back as f(ctx, error). """
    import sys
    if not sys.modules.has_key('libxslt'):
        # normal behaviour when libxslt is not imported
        ret = libxml2mod.xmlRegisterErrorHandler(f,ctx)
    else:
        # when libxslt is already imported, one must
        # use libxst's error handler instead
        import libxslt
        ret = libxslt.registerErrorHandler(f,ctx)
    return ret