Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename the files according to book secionts
- Loading branch information
1 parent
43aa1b8
commit 130e55e
Showing
26 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
<Ships> | |||
<Class name="Kongo" type="be" country="Japan" numGuns="8" bore="14" displacement="32000"> | |||
<Ship name="Kongo" launched="1913"/> | |||
<Ship name="Hiei" launched="1914"/> | |||
<Ship name="Kirishima" launched="1915"> | |||
<Battle outcome="sunk">Guadalcanal</Battle> | |||
</Ship> | |||
<Ship name="Haruna" launched="1915"/> | |||
</Class> | |||
<Class name="North Carolina" type="bb" country="USA" numGuns="9" bore="16" displacement="37000"> | |||
<Ship name="North Carolina" launched="1941"/> | |||
<Ship name="Washington" launched="1941"> | |||
<Battle outcome="ok">Guadalcanal</Battle> | |||
</Ship> | |||
</Class> | |||
<Class name="Tennessee" type="bb" country="USA" numGuns="12" bore="14" displacement="32000"> | |||
<Ship name="Tennessee" launched="1920"> | |||
<Battle outcome="ok">Surigao Strait</Battle> | |||
</Ship> | |||
<Ship name="California" launched="1921"> | |||
<Battle outcome="ok">Surigao Strait</Battle> | |||
</Ship> | |||
</Class> | |||
<Class name="King George V" type="bb" country="Great Britain" numGuns="10" bore="14" displacement="32000"> | |||
<Ship name="King George V" launched="1940"/> | |||
<Ship name="Prince of Wales" launched="1941"> | |||
<Battle outcome="damaged">Denmark Strait</Battle> | |||
<Battle outcome="sunk">Malaya</Battle> | |||
</Ship> | |||
<Ship name="Duke of York" launched="1941"> | |||
<Battle outcome="ok">North Cape</Battle> | |||
</Ship> | |||
<Ship name="Howe" launched="1942"/> | |||
<Ship name="Anson" launched="1942"/> | |||
</Class> | |||
</Ships> |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
<Movies> | |||
<Movie title="KingKong"> | |||
<Version year="1933"> | |||
<Star>Carrie Fisher</Star> | |||
</Version> | |||
<Version year="1976"> | |||
<Star>JeffBridges</Star> | |||
<Star>JessicaLange</Star> | |||
</Version> | |||
<Version year="2005"/> | |||
<Version year="1984"> | |||
<Star>Carrie Fisher</Star> | |||
<Star>John Lithgow</Star> | |||
<Star>Sarah Jessica Parker</Star> | |||
</Version> | |||
</Movie> | |||
</Movies> |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
<Products> | |||
<Maker name="A"> | |||
<PC model="1001" price="2114"> | |||
<Speed>2. 66</Speed> | |||
<RAM>1024</RAM> | |||
<HardDisk>250</HardDisk> | |||
</PC> | |||
<PC model="1002" price="995"> | |||
<Speed>2. 10</Speed> | |||
<RAM>512</RAM> | |||
<HardDisk>250</HardDisk> | |||
</PC> | |||
<Laptop model="2004" price="1150"> | |||
<Speed>2. 00</Speed> | |||
<RAM>512</RAM> | |||
<HardDisk>60</HardDisk> | |||
<Screen>13. 3</Screen> | |||
</Laptop> | |||
<Laptop model="2005" price="2500"> | |||
<Speed>2. 16</Speed> | |||
<RAM>1024</RAM> | |||
<HardDisk>120</HardDisk> | |||
<Screen>17.0</Screen> | |||
</Laptop> | |||
</Maker> | |||
<Maker name="E"> | |||
<PC model="1011" price="959"> | |||
<Speed>l.86</Speed> | |||
<RAM>2048</RAM> | |||
<HardDisk>160</HardDisk> | |||
</PC> | |||
<PC model="1012" price="649"> | |||
<Speed>2. 80</Speed> | |||
<RAM>1024</RAM> | |||
<HardDisk>160</HardDisk> | |||
</PC> | |||
<Laptop model="2001" price="3673"> | |||
<Speed>2. 00</Speed> | |||
<RAM>2048</RAM> | |||
<HardDisk>240</HardDisk> | |||
<Screen>20.1</Screen> | |||
</Laptop> | |||
<Printer model="3002" price="239"> | |||
<Color>false</Color> | |||
<Type>laser</Type> | |||
</Printer> | |||
</Maker> | |||
<Maker name="H"> | |||
<Printer model="3006" price="100"> | |||
<Color>true</Color> | |||
<Type>ink-jet</Type> | |||
</Printer> | |||
<Printer model="3007" price="200"> | |||
<Color>true</Color> | |||
<Type>laser</Type> | |||
</Printer> | |||
</Maker> | |||
</Products> |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
<?xml version="1.0"?> | |||
<Stars> | |||
<Star> | |||
<Name>Carrie Fisher</Name> | |||
<Address> | |||
<Street>123 Maple St.</Street> | |||
<City>Hollywood</City> | |||
</Address> | |||
<Address> | |||
<Street>5 Locust Ln.</Street> | |||
<City>Malibu</City> | |||
</Address> | |||
</Star> | |||
<Star> | |||
<Name>David Pool</Name> | |||
<Address> | |||
<Street>123 Maple St.</Street> | |||
<City>Malibu</City> | |||
</Address> | |||
<Address> | |||
<Street>5 Locust Ln.</Street> | |||
<City>Malibu</City> | |||
</Address> | |||
</Star> | |||
</Stars> | |||
|
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,72 @@ | |||
(: fetch data through an interation :) | |||
let $movies := doc('movies.xml') | |||
for $m in $movies/Movies/Movie | |||
return <Movie>{ $m/Version/Star }</Movie> | |||
|
|||
(: replace variables by its value :) | |||
let $movies := doc('movies.xml') | |||
for $m in $movies/Movies/Movie | |||
return <Movie title = "{$m/@title}">{$m/Version/Star}</Movie> | |||
|
|||
(: put tags around a sequence :) | |||
let $starReq := ( | |||
let $movies := doc('movies.xml') | |||
for $m in $movies/Movies/Movie | |||
return $m/Version/Star | |||
) | |||
return <Star>{ $starReq }</Star> | |||
|
|||
(: use join in xquery :) | |||
let $movies := doc('movies.xml'), | |||
$stars := doc('stars.xml') | |||
for $s1 in $movies/Movies/Movie/Version/Star, | |||
$s2 in $stars/Stars/Star | |||
where data($s1) = data($s2/Name) | |||
return <Cities>{ $s2/Address/City }</Cities> | |||
|
|||
(: erronous comparison examples :) | |||
(: because = stands: some item in the sequence matches... :) | |||
let $stars := doc('stars.xml') | |||
for $s in $stars/Stars/Star | |||
where $s/Address/Street = '123 Maple St.' | |||
and $s/Address/City = 'Malibu' | |||
return $s/Name | |||
|
|||
(: another erronous comparison, because eq only allows for single item :) | |||
let $stars := doc('stars.xml') | |||
for $s in $stars/Stars/Star | |||
where $s/Address/Street eq '123 Maple St.' | |||
and $s/Address/City eq 'Malibu' | |||
return $s/Name | |||
|
|||
|
|||
(: distinct stars, for a string sequence :) | |||
let $starReq := distinct-values( | |||
let $movies := doc('movies.xml') | |||
for $m in $movies/Movies/Movie | |||
return $m/Version/Star | |||
) | |||
return <Star>{ $starReq }</Star> | |||
|
|||
(: qualification in xquery :) | |||
let $stars := doc('stars.xml') | |||
for $s in $stars/Stars/Star | |||
where every $c in $s/Address/City satisfies | |||
$c = 'Malibu' | |||
return $s/Name | |||
|
|||
(: by default the comparison follows the 'some' logic :) | |||
let $stars := doc('stars.xml') | |||
return <Name> | |||
{ | |||
for $s in $stars/Stars/Star | |||
where $s/Address/City = 'Malibu' | |||
return $s/Name | |||
} | |||
</Name> | |||
|
|||
(: aggregation functions :) | |||
let $movies := doc('movies.xml') | |||
for $m in $movies/Movies/Movie | |||
where count($m/Version) > 1 | |||
return $m |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
#!/bin/bash | |||
result=`exec java -cp /usr/local/Cellar/saxon/9.4.0.6/libexec/saxon9he.jar net.sf.saxon.Query "$@"` | |||
if echo $result | xmllint --format - &> /dev/null | |||
# format the output if it is valid xml | |||
then echo $result | xmllint --format - | |||
else echo $result | |||
fi |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
#!/bin/bash | |||
exec java -cp /usr/local/Cellar/saxon/9.4.0.6/libexec/saxon9he.jar net.sf.saxon.Transform "$@" |