Exemple #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
Exemple #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
Exemple #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
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
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