Created
January 31, 2015 17:40
-
-
Save tyrion/36bd249c01e2589f32d2 to your computer and use it in GitHub Desktop.
Madness of XQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare function local:maxconsecutive($partite as element()*, $squadra as xs:string, $i as xs:integer, $max as xs:integer, $tot as xs:integer) as xs:integer { | |
(if ($i = count($partite)+1) then ( local:max($max, $tot)) | |
else ( | |
if (local:vinta($partite[$i], $squadra)) | |
then (local:maxconsecutive($partite, $squadra, $i+1, $max+1, $tot)) | |
else (local:maxconsecutive($partite, $squadra, $i+1, 0, local:max($max, $tot))) | |
)) | |
}; | |
declare function local:max($a as xs:integer, $b as xs:integer) as xs:integer { | |
(if ($a >= $b) then ($a) else ($b)) | |
}; | |
declare function local:vinta($partita, $squadra) as xs:boolean { | |
(($partita/squadracasa = $squadra and $partita/goalcasa > $partita/goalospite) or | |
($partita/squadraospite = $squadra and $partita/goalcasa < $partita/goalospite)) | |
}; | |
let $partite := doc("partite.xml")//partita | |
return local:maxconsecutive($partite, string("roma"), 1, 0, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recursion FTW!