Exemple #1
0
def apply_xsl(mml, xsl):
    """Apply a xsl to a MathML string
    @param mml: a string with MathML code
    @param xsl: a string representing a path to a xsl (xml stylesheet)
        file. This file name is relative to the PYTHONPATH

    >>> from sympy.utilities.mathml import apply_xsl
    >>> xsl = 'mathml/data/simple_mmlctop.xsl'
    >>> mml = '<apply> <plus/> <ci>a</ci> <ci>b</ci> </apply>'
    >>> res = apply_xsl(mml,xsl)
    >>> ''.join(res.splitlines())
    '<?xml version="1.0"?><mrow xmlns="http://www.w3.org/1998/Math/MathML">  <mi>a</mi>  <mo> + </mo>  <mi>b</mi></mrow>'

    """
    from lxml import etree
    s = etree.XML(get_resource(xsl).read())
    transform = etree.XSLT(s)
    doc = etree.XML(mml)
    result = transform(doc)
    s = str(result)
    return s
def apply_xsl(mml, xsl):
    """Apply a xsl to a MathML string
    @param mml: a string with MathML code
    @param xsl: a string representing a path to a xsl (xml stylesheet)
        file. This file name is relative to the PYTHONPATH

    >>> from sympy.utilities.mathml import apply_xsl
    >>> xsl = 'mathml/data/simple_mmlctop.xsl'
    >>> mml = '<apply> <plus/> <ci>a</ci> <ci>b</ci> </apply>'
    >>> res = apply_xsl(mml,xsl)
    >>> ''.join(res.splitlines())
    '<?xml version="1.0"?><mrow xmlns="http://www.w3.org/1998/Math/MathML">  <mi>a</mi>  <mo> + </mo>  <mi>b</mi></mrow>'

    """
    from lxml import etree
    s = etree.XML(get_resource(xsl).read())
    transform = etree.XSLT(s)
    doc = etree.XML(mml)
    result = transform(doc)
    s = str(result)
    return s
Exemple #3
0
def apply_xsl(mml, xsl):
    """Apply a xsl to a MathML string
    @param mml: a string with MathML code
    @param xsl: a string representing a path to a xsl (xml stylesheet)
        file. This file name is relative to the PYTHONPATH
    """

    import libxml2
    import libxslt

    s = get_resource(xsl).read()

    styledoc = libxml2.parseDoc(s)
    style = libxslt.parseStylesheetDoc(styledoc)

    doc = libxml2.parseDoc(mml)
    result = style.applyStylesheet(doc, None)
    sourceDoc = result
    s = style.saveResultToString(result)

    style.freeStylesheet()
    sourceDoc.freeDoc()

    return s