def get_creation_date_libxslt(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"): """ libxslt extension function: Bridge between BibFormat and XSL stylesheets. Returns record creation date. Can be used in that way in XSL stylesheet (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared): <xsl:value-of select="fn:creation_date(445)"/> where 445 is a recID if recID is string, value is converted to int if recID is Node, first child node (text node) is taken as value """ try: if isinstance(recID, str): recID_int = int(recID) elif isinstance(recID, (int, long)): recID_int = recID else: recID_int = libxml2.xmlNode(_obj=recID[0]).children.content if isinstance(fmt, str): fmt_str = fmt else: fmt_str = libxml2.xmlNode(_obj=recID[0]).children.content return get_creation_date(recID_int, fmt_str) except Exception, err: sys.stderr.write("Error during formatting function evaluation: " + \ str(err) + \ '\n') return ''
def get_creation_date_4suite(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"): """ 4suite extension function: Bridge between BibFormat and XSL stylesheets. Returns record creation date. Can be used in that way in XSL stylesheet (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared): <xsl:value-of select="fn:creation_date(445)"/> 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(recID) > 0 and isinstance(recID[0], Node): recID_int = recID[0].firstChild.nodeValue if recID_int is None: return '' else: recID_int = int(recID) if len(fmt) > 0 and isinstance(fmt[0], Node): fmt_str = fmt[0].firstChild.nodeValue if fmt_str is None: fmt_str = "%Y-%m-%dT%H:%M:%SZ" else: fmt_str = str(fmt) return get_creation_date(recID_int, fmt_str) except Exception, err: sys.stderr.write("Error during formatting function evaluation: " + \ str(err) + \ '\n') return ''
def get_creation_date_lxml(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"): """ libxslt extension function: Bridge between BibFormat and XSL stylesheets. Returns record creation date. Can be used in that way in XSL stylesheet (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared): <xsl:value-of select="fn:creation_date(445)"/> where 445 is a recID if recID is string, value is converted to int if recID is Node, first child node (text node) is taken as value @param ctx: context as passed by lxml @param recID: record ID @param fmt: format of the returned date @return: creation date of X{recID} @rtype: string """ try: if isinstance(recID, str): recID_int = int(recID) elif isinstance(recID, (int, long)): recID_int = recID elif isinstance(recID, list): recID = recID[0] if isinstance(recID, str): recID_int = int(recID) else: recID_int = int(recID.text) else: recID_int = int(recID.text) if isinstance(fmt, str): fmt_str = fmt elif isinstance(fmt, list): fmt = fmt[0] if isinstance(fmt, str): fmt_str = fmt else: fmt_str = fmt.text else: fmt_str = fmt.text return get_creation_date(recID_int, fmt_str) except Exception, err: sys.stderr.write("Error during formatting function evaluation: " + \ str(err) + \ '\n') return ''