Last active
January 12, 2017 22:07
-
-
Save joewiz/494875ac1b8b45661333f25d18a813b4 to your computer and use it in GitHub Desktop.
Find travels of the Secretary of State that took place within 8 days of inauguration
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
xquery version "3.1"; | |
let $all-secretary-travels := collection('/db/apps/travels/secretary-travels')//trip | |
let $days-before-inauguration := 8 | |
let $duration := xs:dayTimeDuration("P" || $days-before-inauguration || "D") | |
let $presidents := doc("/db/apps/travels/presidents/presidents.xml")//president | |
for $president in $presidents | |
let $inauguration-date := xs:date($president/took-office-date) | |
let $travels-within-period-before-inauguration := | |
for $trip in $all-secretary-travels | |
let $start-date := xs:date($trip/start-date) | |
let $end-date := xs:date($trip/end-date) | |
return | |
if | |
( | |
( | |
$end-date le $inauguration-date | |
and | |
$inauguration-date - $end-date le $duration | |
) | |
or | |
( | |
$start-date le $inauguration-date | |
and | |
$inauguration-date - $start-date le $duration | |
) | |
) | |
then | |
$trip | |
else | |
() | |
return | |
if ($travels-within-period-before-inauguration) then | |
element result { $president, $travels-within-period-before-inauguration } | |
else | |
() |
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
<results> | |
<result> | |
<president n="41"> | |
<id>bush-george-h-w</id> | |
<name>George H. W. Bush</name> | |
<birth-year>1924</birth-year> | |
<death-year still-alive="true"/> | |
<took-office-date>1989-01-20</took-office-date> | |
<left-office-date>1993-01-20</left-office-date> | |
<created-by>admin</created-by> | |
<created-date>2011-08-18</created-date> | |
<last-modified-by>admin</last-modified-by> | |
<last-modified-date>2011-08-18</last-modified-date> | |
</president> | |
<trip who="shultz-george-pratt" role="secretary"> | |
<id>2188</id> | |
<role>secretary</role> | |
<name>George Pratt Shultz</name> | |
<start-date>1989-01-16</start-date> | |
<end-date>1989-01-18</end-date> | |
<country id="austria">Austria</country> | |
<locale>Vienna</locale> | |
<remarks>Attended the closing session of the CSCE Follow-up Meeting. </remarks> | |
<created-by>joewiz</created-by> | |
<created-datetime>2010-02-27T12:35:48.889-06:00</created-datetime> | |
<last-modified-by>joewiz</last-modified-by> | |
<last-modified-datetime>2010-02-27T12:35:48.889-06:00</last-modified-datetime> | |
</trip> | |
</result> | |
<result> | |
<president n="43"> | |
<id>bush-george-w</id> | |
<name>George W. Bush</name> | |
<birth-year>1946</birth-year> | |
<death-year still-alive="true"/> | |
<took-office-date>2001-01-20</took-office-date> | |
<left-office-date>2009-01-20</left-office-date> | |
<created-by>admin</created-by> | |
<created-date>2011-08-18</created-date> | |
<last-modified-by>admin</last-modified-by> | |
<last-modified-date>2011-08-18</last-modified-date> | |
</president> | |
<trip who="albright-madeleine-korbel" role="secretary"> | |
<id>269</id> | |
<role>secretary</role> | |
<name>Madeleine Korbel Albright</name> | |
<start-date>2001-01-11</start-date> | |
<end-date>2001-01-13</end-date> | |
<country id="france">France</country> | |
<locale>Paris</locale> | |
<remarks>Met with Foreign Minister Vedrine and other European Foreign Ministers. </remarks> | |
<created-by>joewiz</created-by> | |
<created-datetime>2010-02-27T12:35:48.889-06:00</created-datetime> | |
<last-modified-by>joewiz</last-modified-by> | |
<last-modified-datetime>2010-02-27T12:35:48.889-06:00</last-modified-datetime> | |
</trip> | |
</result> | |
</results> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment