Example #1
0
def bibconvert_function_libxslt(ctx, value, func):
    """
    libxslt extension function:
    Bridge between BibConvert formatting functions and XSL stylesheets.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibconvert/fn" has been declared):
    <xsl:value-of select="fn:format(., 'ADD(mypref,mysuff)')"/>
    (Adds strings 'mypref' and 'mysuff' as prefix/suffix to current node value,
    using BibConvert ADD function)

    if value is int, value is converted to string
    if value is Node (PyCObj), first child node (text node) is taken as value
    """
    try:
        if isinstance(value, str):
            string_value = value
        elif isinstance(value, (int, long)):
            string_value = str(value)
        else:
            string_value = libxml2.xmlNode(_obj=value[0]).children.content

        return FormatField(string_value, func).rstrip('\n')

    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')
Example #2
0
def bibconvert_function_4suite(ctx, value, func):
    """
    4suite extension function:
    Bridge between BibConvert formatting functions and XSL stylesheets.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibconvert/fn" has been declared):
    <xsl:value-of select="fn:format(., 'ADD(mypref,mysuff)')"/>
    (Adds strings 'mypref' and 'mysuff' as prefix/suffix to current node value,
    using BibConvert ADD function)

    if value is int, value is converted to string
    if value is Node, first child node (text node) is taken as value
    """
    try:
        if len(value) > 0 and isinstance(value[0], Node):
            string_value = value[0].firstChild.nodeValue
            if string_value is None:
                string_value = ''
        else:
            string_value = str(value)

        return FormatField(string_value, func).rstrip('\n')

    except Exception, err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')