Reputation: 51
I want to extract all values of a column from a table, determine the maximum of those values, and return that value.
This is what I tried:
let $abc := doc("file:///some_local_file")//AOSCAT_MetricDetail//table[@class="pretty-table"]//tr/td[13]
return <li>{ fn:max(fn:substring($abc,1,1)) }</li>
But fn:substring can't handle a sequence of more than one item.
So I tried this:
let $set_all_mbd := doc("file:///some_local_file")//AOSCAT_MetricDetail//table[@class="pretty-table"]//tr/td[13]
for $xyz in $set_all_mbd
let $abc := fn:substring($xyz,1,1)
return <li>{ fn:max($abc) }</li>
It returns for every row of the table though, and I want just one single value returned.
I suppose this is very simple but XQuery is new to me and can't figure out how to do it...
Upvotes: 0
Views: 199
Reputation: 122374
If you want to apply substring
to each item in the sequence, try
let $abc := doc("file:///some_local_file")//AOSCAT_MetricDetail//table[@class="pretty-table"]//tr/td[13]
return <li>{ max($abc/substring(.,1,1)) }</li>
(untested).
If that doesn't work then you can definitely do it with an explicit for
:
let $abc := doc("file:///some_local_file")//AOSCAT_MetricDetail//table[@class="pretty-table"]//tr/td[13]
return <li>{ max(for $x in $abc return substring($x,1,1)) }</li>
Upvotes: 1