mb_language("uni"); mb_internal_encoding("utf-8"); mb_http_input("auto"); mb_http_output("utf-8"); ?>
<?xml version="1.0" encoding="utf-8"?> <weather-data prefecture="tokyo" area="tokyo"> <weather date='2012-01-01' hour='15'> <condition>曇</condition><pressure_hpa>1012.8</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>8.0</temperature_c><humidity>37</humidity> <wind><speed_ms>2.8</speed_ms><direction>北西</direction></wind> </weather> <weather date='2012-01-02' hour='15'> <condition>快晴</condition><pressure_hpa>1003.2</pressure_hpa> <rainfall_mm>0.0</rainfall_mm> <temperature_c>10.4</temperature_c><humidity>28</humidity> <wind><speed_ms>5.6</speed_ms><direction>北北西</direction></wind> </weather> <weather date='2012-01-03' hour='15'> <condition>晴</condition><pressure_hpa>1006.3</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>9.8</temperature_c><humidity>21</humidity> <wind><speed_ms>4.4</speed_ms><direction>北北西</direction></wind> </weather> <weather date='2012-01-04' hour='15'> <condition>晴</condition><pressure_hpa>998.2</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>8.5</temperature_c><humidity>33</humidity> <wind><speed_ms>4.4</speed_ms><direction>北北西</direction></wind> </weather> <weather date='2012-01-05' hour='15'> <condition>快晴</condition><pressure_hpa>1010.4</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>8.6</temperature_c><humidity>17</humidity> <wind><speed_ms>6.7</speed_ms><direction>北西</direction></wind> </weather> <weather date='2012-01-06' hour='15'> <condition>快晴</condition><pressure_hpa>1014.8</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>9.4</temperature_c><humidity>35</humidity> <wind><speed_ms>2.5</speed_ms><direction>南南東</direction></wind> </weather> <weather date='2012-01-07' hour='15'> <condition>快晴</condition><pressure_hpa>1018.9</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>8.5</temperature_c><humidity>20</humidity> <wind><speed_ms>5.0</speed_ms><direction>北北西</direction></wind> </weather> </weather-data>
<?xml version="1.0" encoding="utf-8"?> <weather-data prefecture="osaka" area="osaka"> <weather date='2012-01-01' hour='15'> <condition>晴</condition><pressure_hpa>1007.7</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>11.0</temperature_c><humidity>48</humidity> <wind><speed_ms>3.3</speed_ms><direction>西南西</direction></wind> </weather> <weather date='2012-01-02' hour='15'> <condition>雨</condition><pressure_hpa>1007.8</pressure_hpa> <rainfall_mm>0.0</rainfall_mm> <temperature_c>7.0</temperature_c><humidity>51</humidity> <wind><speed_ms>4.8</speed_ms><direction>北北西</direction></wind> </weather> <weather date='2012-01-03' hour='15'> <condition>曇</condition><pressure_hpa>1004.5</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>7.6</temperature_c><humidity>54</humidity> <wind><speed_ms>4.1</speed_ms><direction>西</direction></wind> </weather> <weather date='2012-01-04' hour='15'> <condition>曇</condition><pressure_hpa>1001.4</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>6.0</temperature_c><humidity>38</humidity> <wind><speed_ms>10.1</speed_ms><direction>西北西</direction></wind> </weather> <weather date='2012-01-05' hour='15'> <condition>晴</condition><pressure_hpa>1011.8</pressure_hpa> <rainfall_mm>0.0</rainfall_mm> <temperature_c>6.3</temperature_c><humidity>53</humidity> <wind><speed_ms>2.8</speed_ms><direction>北北西</direction></wind> </weather> <weather date='2012-01-06' hour='15'> <condition>晴</condition><pressure_hpa>1013.0</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>9.0</temperature_c><humidity>42</humidity> <wind><speed_ms>3.6</speed_ms><direction>西南西</direction></wind> </weather> <weather date='2012-01-07' hour='15'> <condition>晴</condition><pressure_hpa>1018.8</pressure_hpa> <rainfall_mm>--</rainfall_mm> <temperature_c>7.2</temperature_c><humidity>43</humidity> <wind><speed_ms>4.7</speed_ms><direction>北西</direction></wind> </weather> </weather-data>
/ND/weather-data
{-- 2012年1月4日の東京の気象情報 --} /ND/weather-data[@prefecture="tokyo"]/weather[@date="2012-01-04"]
{-- 2012年1月4日の東京の気象情報 --} for $w in /ND/weather-data[@prefecture="tokyo"]/weather[@date="2012-01-04"] return $w
{-- 2012年1月4日の東京の気象情報(無理やりletとWhere使用) --} for $w in /ND/weather-data/weather let $wd := $w/.. where $wd/@prefecture="tokyo" and $w/@date="2012-01-04" return $w
{-- 2012年1月4日の東京の気象情報を検索し、見やすい文書に加工 --} for $w in /ND/weather-data[@prefecture="tokyo"]/weather[@date="2012-01-04"] return <東京の天気 date={$w/@date} hour={$w/@hour}> <天気>{$w/condition/text()}</天気> <気温>{$w/temperature_c/text()}℃</気温> <湿度>{$w/humidity/text()}%</湿度> </東京の天気>
{-- 大阪の方が気温が高かった日を検索し、見やすい文書に加工--} for $wt in //weather-data[@prefecture="tokyo"]/weather for $wo in //weather-data[@prefecture="osaka"]/weather {-- let $wo := でも同じ --} where $wt/@date=$wo/@date {-- 同じ日付で比較 --} and number($wt/temperature_c) < number($wo/temperature_c) return <気温 date={$wt/@date} hour={$wt/@hour}> <東京>{$wt/temperature_c/text()}℃</東京> <大阪>{$wo/temperature_c/text()}℃</大阪> </気温>
{-- 無理やり入れ子化 --} for $w in (for $x in /ND/weather-data where $x/@prefecture="tokyo" return $x)/weather where $w/@date="2012-01-04" return <東京の天気 date={$w/@date} hour={$w/@hour}> <天気>{$w/condition/text()}</天気> <気温>{$w/temperature_c/text()}℃</気温> <湿度>{$w/humidity/text()}%</湿度> </東京の天気>
<天気CSV> <header>都道府県,日付,時刻,天気,温度</header> { for $w in /ND/weather-data[@prefecture="tokyo"]/weather sortby (@date descending) return <row>東京,{$w/@date/text()},15時,{$w/condition/text()},{$w/temperature_c/text()}℃ </row> } { for $w in /ND/weather-data[@prefecture="osaka"]/weather sortby (@date descending) return <row>大阪,{$w/@date/text()},15時,{$w/condition/text()},{$w/temperature_c/text()}℃ </row> } </天気CSV>
▲このページのTOPへ