Permalink
Browse files

rename the files according to book secionts

  • Loading branch information...
1 parent 43aa1b8 commit 130e55e4279ca6b77a562360f9be07740b8b8edf @yangchenyun committed Mar 27, 2013
Showing with 218 additions and 0 deletions.
  1. +36 −0 12.xml-examples/battle_ships.xml
  2. +17 −0 12.xml-examples/movies.xml
  3. +58 −0 12.xml-examples/products.xml
  4. +26 −0 12.xml-examples/stars.xml
  5. +72 −0 12.xml-examples/xquery-example.xq
  6. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1a.ra
  7. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1b.ra
  8. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1c.ra
  9. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1d.ra
  10. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1e.ra
  11. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1f.ra
  12. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1g.ra
  13. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1h.ra
  14. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1i.ra
  15. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1j.ra
  16. 0 {book-2.4-computer-database → 2.4-computer-database}/2.4.1k.ra
  17. BIN {book-2.4-computer-database → 2.4-computer-database}/sample.db
  18. 0 {book-2.4-computer-database → 2.4-computer-database}/sample.properties
  19. 0 {book-2.4-computer-database → 2.4-computer-database}/sample.ra
  20. BIN {book-2.4-world-war-II → 2.4-world-war-ii}/sample.db
  21. 0 {book-2.4-world-war-II → 2.4-world-war-ii}/sample.properties
  22. 0 {book-2.4-world-war-II → 2.4-world-war-ii}/sample.ra
  23. 0 {book-2.4-world-war-II → 2.4-world-war-ii}/sample.ra.erb
  24. 0 { → bin}/ra
  25. +7 −0 bin/xquery
  26. +2 −0 bin/xslt
@@ -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>
View
@@ -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>
@@ -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>
View
@@ -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>
+
@@ -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.
View
File renamed without changes.
View
@@ -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
View
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec java -cp /usr/local/Cellar/saxon/9.4.0.6/libexec/saxon9he.jar net.sf.saxon.Transform "$@"

0 comments on commit 130e55e

Please sign in to comment.