def fn_dateTime(xc, p, contextItem, args): if len(args) != 2: raise XPathContext.FunctionNumArgs() date = anytypeArg(xc, args, 0, "xs:date", missingArgFallback=()) time = anytypeArg(xc, args, 1, "xs:time", missingArgFallback=()) if date is None or time is None: return () return dateTime(date) + dayTimeDuration(time)
def instance(xc, p, args, i=0): if len(args[i]) != 1: raise XPathContext.FunctionArgType(i + 1, "xbrl:xbrl") modelXbrl = xc.modelInstance(anytypeArg(xc, args, i, "xbrli:xbrl")) if modelXbrl: return modelXbrl raise XPathContext.FunctionArgType(i + 1, "xbrl:xbrl")
def element_name(xc, p, args, elementParent=False): if len(args) != 1: raise XPathContext.FunctionNumArgs() modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None) if modelRel is None: raise XPathContext.FunctionArgType(1,"arelle:modelRelationship") element = modelRel.arcElement if elementParent: element = element.getparent() return qname(element)
def base_uri(xc, p, contextItem, args): item = anytypeArg(xc, args, 0, "node()?", missingArgFallback=contextItem) if item == (): return '' if isinstance(item, (ModelObject, ModelDocument)): return UrlUtil.ensureUrl(item.modelDocument.uri) return ''
def seconds_from_duration(xc, p, contextItem, args): if len(args) != 1: raise XPathContext.FunctionNumArgs() d = anytypeArg(xc, args, 0, 'duration', missingArgFallback=()) if d == (): return d if isinstance(d, DayTimeDuration): return 0 if isinstance(d, YearMonthDuration): return d.dayHrsMinsSecs[2] raise XPathContext.FunctionArgType(1,"xs:duration")
def element_name(xc, p, args, elementParent=False): if len(args) != 1: raise XPathContext.FunctionNumArgs() modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None) if not modelRel: raise XPathContext.FunctionArgType(1, "arelle:modelRelationship") element = modelRel.element if elementParent: element = element.parentNode return qname(element)
def concat(xc, p, contextItem, args): if len(args) < 2: raise XPathContext.FunctionNumArgs() atomizedArgs = [] for i in range(len(args)): item = anytypeArg(xc, args, i, "xs:anyAtomicType?") if item != (): atomizedArgs.append( FunctionXs.xsString( xc, p, xc.atomize(p, item) ) ) return ''.join(atomizedArgs)
def relationship_element_attribute(xc, p, args, elementParent=False): if len(args) != 2: raise XPathContext.FunctionNumArgs() modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None) if modelRel is None: raise XPathContext.FunctionArgType(1,"arelle:modelRelationship") qnAttr = qnameArg(xc, p, args, 1, 'QName', emptyFallback=None) if qnAttr is None: raise XPathContext.FunctionArgType(2,"xs:QName") element = modelRel.arcElement if elementParent: element = element.getparent() return element_attribute(element, qnAttr)
def string(xc, p, contextItem, args): if len(args) > 1: raise XPathContext.FunctionNumArgs() item = anytypeArg(xc, args, 0, "item()?", missingArgFallback=contextItem) if item == (): return '' if isinstance(item, ModelObject) and getattr(item,"xValid", 0) == VALID_NO_CONTENT: x = item.stringValue # represents inner text of this and all subelements else: x = xc.atomize(p, item) return FunctionXs.xsString( xc, p, x )
def string(xc, p, contextItem, args): if len(args) > 1: raise XPathContext.FunctionNumArgs() item = anytypeArg(xc, args, 0, "item()?", missingArgFallback=contextItem) if item == (): return '' if isinstance(item, ModelObject) and getattr(item, "xValid", 0) == VALID_NO_CONTENT: x = item.stringValue # represents inner text of this and all subelements else: x = xc.atomize(p, item) return FunctionXs.xsString(xc, p, x)
def element_attribute(xc, p, args, elementParent=False): if len(args) != 2: raise XPathContext.FunctionNumArgs() modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None) if not modelRel: raise XPathContext.FunctionArgType(1,"arelle:modelRelationship") qnAttr = qnameArg(xc, p, args, 1, 'QName', emptyFallback=None) if not qnAttr: raise XPathContext.FunctionArgType(2,"xs:QName") element = modelRel.element if elementParent: element = element.parentNode if qnAttr.namespaceURI: if not element.hasAttributeNS(qnAttr.namespaceURI, qnAttr.localName): return () return xc.atomize(p, element.getAttributeNodeNS(qnAttr.namespaceURI, qnAttr.localName)) else: if not element.hasAttribute(qnAttr.localName): return () return xc.atomize(p, element.getAttributeNode(qnAttr.localName))
def element_attribute(xc, p, args, elementParent=False): if len(args) != 2: raise XPathContext.FunctionNumArgs() modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None) if not modelRel: raise XPathContext.FunctionArgType(1, "arelle:modelRelationship") qnAttr = qnameArg(xc, p, args, 1, 'QName', emptyFallback=None) if not qnAttr: raise XPathContext.FunctionArgType(2, "xs:QName") element = modelRel.element if elementParent: element = element.parentNode if qnAttr.namespaceURI: if not element.hasAttributeNS(qnAttr.namespaceURI, qnAttr.localName): return () return xc.atomize( p, element.getAttributeNodeNS(qnAttr.namespaceURI, qnAttr.localName)) else: if not element.hasAttribute(qnAttr.localName): return () return xc.atomize(p, element.getAttributeNode(qnAttr.localName))
def relationship_to_concept(xc, p, args): if len(args) != 1: raise XPathContext.FunctionNumArgs() modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None) if modelRel is not None: return modelRel.toModelObject.qname raise XPathContext.FunctionArgType(1,"arelle:modelRelationship")
def timezone_from_time(xc, p, contextItem, args): if len(args) != 1: raise XPathContext.FunctionNumArgs() d = anytypeArg(xc, args, 0, 'time', missingArgFallback=()) if d == (): return d if isinstance(d, Time): return d.tzinfo raise XPathContext.FunctionArgType(1,"xs:time")
def day_from_date(xc, p, contextItem, args): if len(args) != 1: raise XPathContext.FunctionNumArgs() d = anytypeArg(xc, args, 0, 'dateTime', missingArgFallback=()) if d == (): return d if isinstance(d, DateTime): return d.day raise XPathContext.FunctionArgType(1,"xs:dateTime")
def instance(xc, p, args, i=0): if len(args[i]) != 1: raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl") modelXbrl = xc.modelInstance(anytypeArg(xc, args, i, "xbrli:xbrl")) if modelXbrl: return modelXbrl raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl")
def instance(xc, p, args, i=0): if len(args[i]) != 1: raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl") xbrliXbrl = anytypeArg(xc, args, i, "xbrli:xbrl") if isinstance(xbrliXbrl, ModelObject) and xbrliXbrl.elementQname == XbrlConst.qnXbrliXbrl: return xbrliXbrl.modelXbrl raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl")
def relationship_to_concept(xc, p, args): if len(args) != 1: raise XPathContext.FunctionNumArgs() modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None) if modelRel: return modelRel.toModelObject.qname raise XPathContext.FunctionArgType(1, "arelle:modelRelationship")