181
183
comp_expr('!=', E1, E2, C) ->
184
?boolean(compare_eq_format(N1,N2,C) == compare_eq_format(N2,N1,C)).
186
?boolean(compare_eq_format(N1,N2,C) /= compare_eq_format(N2,N1,C)).
186
188
bool_expr('or', E1, E2, C) ->
187
189
?boolean(mk_boolean(C, E1) or mk_boolean(C, E2));
284
286
%% node-set: id(object)
286
NS0 = [C#xmlContext.whole_document],
287
case Arg#xmlObj.type of
288
WD = C#xmlContext.whole_document,
290
Obj = mk_object(C,Arg),
291
case Obj#xmlObj.type of
289
NodeSet = Arg#xmlObj.value,
293
NodeSet = Obj#xmlObj.value,
301
305
end, C#xmlContext{nodeset = NS0}),
302
306
?nodeset(NewNodeSet);
304
StrVal = string_value(Arg#xmlObj.value),
308
StrVal = string_value(Obj#xmlObj.value),
305
309
IdTokens = id_tokens(StrVal),
308
select_on_attribute(NS0, id, Tok, AccX)
310
NodeSet = [(WD#xmlNode.node)#xmlDocument.content],
311
NewNodeSet = lists:foldl(
313
select_on_attribute(NodeSet, id, Tok, AccX)
312
319
id_tokens(Str=#xmlObj{type=string}) ->
337
344
local_name1([]) ->
346
local_name1([#xmlNode{type=element,node=El}|_]) ->
347
#xmlElement{name=Name,nsinfo=NSI} = El,
348
local_name2(Name,NSI);
349
local_name1([#xmlNode{type=attribute,node=Att}|_]) ->
350
#xmlAttribute{name=Name,nsinfo=NSI} = Att,
351
local_name2(Name,NSI);
339
352
local_name1([#xmlElement{name = Name, nsinfo = NSI}|_]) ->
353
local_name2(Name,NSI).
354
local_name2(Name, NSI) ->
341
356
{_Prefix, Local} ->
359
?string(atom_to_list(Name))
347
362
%% string: namespace-uri(node-set?)
357
372
ns_uri([#xmlElement{nsinfo = NSI, namespace = NS}|_]) ->
374
ns_uri([#xmlNode{type=element,node=El}|_]) ->
375
#xmlElement{nsinfo=NSI, namespace = NS} = El,
377
ns_uri([#xmlNode{type=attribute,node=Att}|_]) ->
378
#xmlAttribute{nsinfo=NSI, namespace = NS} = Att,
360
386
case lists:keysearch(Prefix, 1, NS#xmlNamespace.nodes) of
363
389
{value, {_K, V}} ->
396
%% name(node-set) -> xmlObj{type=string}
397
%% The name function returns a string containing the QName of the node
398
%% first in document order. The representation of the QName is not
399
%% standardized and applications have their own format. At
400
%% http://xml.coverpages.org/clarkNS-980804.html (the author of XPath)
401
%% adopts the format "namespace URI"+"local-name" but according to
402
%% other sources it is more common to use the format:
403
%% '{'"namespace URI"'}'"local-name". This function also uses this
406
name1(default_nodeset(C));
408
name1(mk_nodeset(C, Arg)).
413
case ns_uri(NodeSet) of
414
#xmlObj{value=NSStr} when NSStr =/= [] ->
419
#xmlObj{value=LocalName} = local_name1(NodeSet),
420
?string(NSVal++LocalName).
372
424
%%% String functions
400
452
TextDecendants=fun(X) -> TextValue(X,TextValue) end,
401
453
?string(lists:flatten(lists:map(TextDecendants,C)));
454
string_value(T=#xmlNode{type=text}) ->
455
#xmlText{value=Txt} = T#xmlNode.node,
402
457
string_value(infinity) -> ?string("Infinity");
403
458
string_value(neg_infinity) -> ?string("-Infinity");
404
459
string_value(A) when atom(A) ->
407
462
?string(integer_to_list(N));
408
463
string_value(N) when float(N) ->
409
464
N1 = round(N * 10000000000000000),
410
?string(strip_zeroes(integer_to_list(N1))).
465
?string(strip_zeroes(integer_to_list(N1)));
466
string_value(Str) when is_list(Str) ->
412
469
strip_zeroes(Str) ->
413
470
strip_zs(lists:reverse(Str), 15).
433
490
%% boolean: starts-with(string, string)
434
491
'starts-with'(C, [A1, A2]) ->
435
?boolean(lists:prefix(mk_string(C, A1), mk_string(C, A2))).
492
?boolean(lists:prefix(mk_string(C, A2), mk_string(C, A1))).
437
494
%% boolean: contains(string, string)
438
495
contains(C, [A1, A2]) ->
613
670
select_on_attribute([E = #xmlElement{attributes = Attrs}|T], K, V, Acc) ->
614
671
case lists:keysearch(K, #xmlAttribute.name, Attrs) of
615
672
{value, #xmlAttribute{value = V}} ->
616
select_on_attribute(T, K, V, [E|Acc]);
673
Acc2 = select_on_attribute(E#xmlElement.content,K,V,[E|Acc]),
674
select_on_attribute(T, K, V, Acc2);
618
select_on_attribute(T, K, V, Acc)
676
Acc2 = select_on_attribute(E#xmlElement.content,K,V,Acc),
677
select_on_attribute(T, K, V, Acc2)
679
select_on_attribute([H|T], K, V, Acc) when is_record(H,xmlText) ->
680
select_on_attribute(T, K, V, Acc);
620
681
select_on_attribute([], _K, _V, Acc) ->
649
710
mk_string(_C0, #xmlObj{type = string, value = V}) ->
712
mk_string(C0, Obj = #xmlObj{}) ->
713
mk_string(C0,string_value(Obj));
651
714
mk_string(C0, Expr) ->
652
715
mk_string(C0, expr(Expr, C0)).