def format_sparql(item, dt_format='turtle', **kwargs):
    """
    Formats a datatype value to a SPARQL representation

    args:
        item: the datatype object
        dt_format: the return format ['turtle', 'uri']
    """
    try:
        rtn_val = json.dumps(item.value)
        rtn_val = item.value
    except:
        if 'time' in item.class_type.lower() \
                or 'date' in item.class_type.lower():
            rtn_val = item.value.isoformat()
        else:
            rtn_val = str(item.value)
    if hasattr(item, "datatype"):
        if hasattr(item, "lang") and item.lang:
            rtn_val = '%s@%s' % (json.dumps(rtn_val), item.lang)
        else:
            dt = item.datatype
            if dt_format == "uri":
                dt = item.datatype.sparql_uri
            if item.datatype in ["xsd_string",
                                 "xsd_dateTime",
                                 "xsd_time",
                                 "xsd_date"]:
                rtn_val = json.dumps(rtn_val)
            else:
                rtn_val = '"%s"' % json.dumps(rtn_val)
            rtn_val = '%s^^%s' % (rtn_val, dt.sparql)
    return rtn_val
Formats a datatype value to a SPARQL representation

    args:
        item: the datatype object
        dt_format: the return format ['turtle', 'uri']