magic_xml 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +22 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/doc/classes/Array.html +148 -0
- data/doc/classes/File.html +113 -0
- data/doc/classes/Hash.html +117 -0
- data/doc/classes/Patterns_all.html +145 -0
- data/doc/classes/Patterns_any.html +145 -0
- data/doc/classes/String.html +470 -0
- data/doc/classes/Symbol.html +145 -0
- data/doc/classes/XML.html +1881 -0
- data/doc/classes/XML_Comment.html +148 -0
- data/doc/classes/XML_PI.html +145 -0
- data/doc/classes/XML_Tests.html +1727 -0
- data/doc/files/magic_xml_rb.html +186 -0
- data/doc/files/simple_examples/xml_hello_f_rb.html +88 -0
- data/doc/files/simple_examples/xml_hello_m_rb.html +88 -0
- data/doc/files/simple_examples/xml_list_f_rb.html +88 -0
- data/doc/files/simple_examples/xml_list_m_rb.html +88 -0
- data/doc/files/tests_rb.html +94 -0
- data/doc/files/xquery_use_cases/parts/q1_rb.html +117 -0
- data/doc/files/xquery_use_cases/rdb/q10_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q11_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q12_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q13_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q14_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q15_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q16_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q17_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q18_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q6_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q7_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q8_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q9_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q10_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q6_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q7_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q8a_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q8b_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q9_rb.html +88 -0
- data/doc/files/xquery_use_cases/solution_sizes_rb.html +88 -0
- data/doc/files/xquery_use_cases/string/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/string/q2_rb.html +93 -0
- data/doc/files/xquery_use_cases/string/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/string/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/test_driver_rb.html +92 -0
- data/doc/files/xquery_use_cases/tree/q1_rb.html +111 -0
- data/doc/files/xquery_use_cases/tree/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q6_rb.html +113 -0
- data/doc/files/xquery_use_cases/xmp/q10_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q11_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q12_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q5_rb.html +92 -0
- data/doc/files/xquery_use_cases/xmp/q6_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q7_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q8_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q9_rb.html +88 -0
- data/doc/fr_class_index.html +56 -0
- data/doc/fr_file_index.html +110 -0
- data/doc/fr_method_index.html +159 -0
- data/doc/index.html +26 -0
- data/doc/rdoc-style.css +175 -0
- data/lib/magic_xml.rb +1400 -0
- data/simple_examples/README +14 -0
- data/simple_examples/xml_hello_f.rb +32 -0
- data/simple_examples/xml_hello_m.rb +32 -0
- data/simple_examples/xml_list_f.rb +36 -0
- data/simple_examples/xml_list_m.rb +36 -0
- data/test/helper.rb +9 -0
- data/test/test_magic_xml.rb +855 -0
- data/xquery_use_cases/README +17 -0
- data/xquery_use_cases/parts/README +12 -0
- data/xquery_use_cases/parts/partlist.xml +13 -0
- data/xquery_use_cases/parts/q1.out +16 -0
- data/xquery_use_cases/parts/q1.rb +38 -0
- data/xquery_use_cases/parts/q1.xquery +18 -0
- data/xquery_use_cases/rdb/README +50 -0
- data/xquery_use_cases/rdb/bids.xml +81 -0
- data/xquery_use_cases/rdb/items.xml +57 -0
- data/xquery_use_cases/rdb/q1.out +10 -0
- data/xquery_use_cases/rdb/q1.rb +31 -0
- data/xquery_use_cases/rdb/q1.xquery +14 -0
- data/xquery_use_cases/rdb/q10.out +27 -0
- data/xquery_use_cases/rdb/q10.rb +37 -0
- data/xquery_use_cases/rdb/q10.xquery +15 -0
- data/xquery_use_cases/rdb/q11.out +7 -0
- data/xquery_use_cases/rdb/q11.rb +38 -0
- data/xquery_use_cases/rdb/q11.xquery +15 -0
- data/xquery_use_cases/rdb/q12.out +12 -0
- data/xquery_use_cases/rdb/q12.rb +42 -0
- data/xquery_use_cases/rdb/q12.xquery +28 -0
- data/xquery_use_cases/rdb/q13.out +32 -0
- data/xquery_use_cases/rdb/q13.rb +45 -0
- data/xquery_use_cases/rdb/q13.xquery +15 -0
- data/xquery_use_cases/rdb/q14.out +14 -0
- data/xquery_use_cases/rdb/q14.rb +42 -0
- data/xquery_use_cases/rdb/q14.xquery +14 -0
- data/xquery_use_cases/rdb/q15.out +5 -0
- data/xquery_use_cases/rdb/q15.rb +31 -0
- data/xquery_use_cases/rdb/q15.xquery +9 -0
- data/xquery_use_cases/rdb/q16.out +35 -0
- data/xquery_use_cases/rdb/q16.rb +35 -0
- data/xquery_use_cases/rdb/q16.xquery +17 -0
- data/xquery_use_cases/rdb/q17.out +1 -0
- data/xquery_use_cases/rdb/q17.rb +35 -0
- data/xquery_use_cases/rdb/q17.xquery +11 -0
- data/xquery_use_cases/rdb/q18.out +32 -0
- data/xquery_use_cases/rdb/q18.rb +40 -0
- data/xquery_use_cases/rdb/q18.xquery +19 -0
- data/xquery_use_cases/rdb/q2.out +22 -0
- data/xquery_use_cases/rdb/q2.rb +36 -0
- data/xquery_use_cases/rdb/q2.xquery +14 -0
- data/xquery_use_cases/rdb/q3.out +8 -0
- data/xquery_use_cases/rdb/q3.rb +34 -0
- data/xquery_use_cases/rdb/q3.xquery +16 -0
- data/xquery_use_cases/rdb/q4.out +14 -0
- data/xquery_use_cases/rdb/q4.rb +31 -0
- data/xquery_use_cases/rdb/q4.xquery +11 -0
- data/xquery_use_cases/rdb/q5.out +12 -0
- data/xquery_use_cases/rdb/q5.rb +46 -0
- data/xquery_use_cases/rdb/q5.xquery +25 -0
- data/xquery_use_cases/rdb/q6.out +14 -0
- data/xquery_use_cases/rdb/q6.rb +38 -0
- data/xquery_use_cases/rdb/q6.xquery +15 -0
- data/xquery_use_cases/rdb/q7.out +1 -0
- data/xquery_use_cases/rdb/q7.rb +30 -0
- data/xquery_use_cases/rdb/q7.xquery +10 -0
- data/xquery_use_cases/rdb/q8.out +1 -0
- data/xquery_use_cases/rdb/q8.rb +23 -0
- data/xquery_use_cases/rdb/q8.xquery +8 -0
- data/xquery_use_cases/rdb/q9.out +22 -0
- data/xquery_use_cases/rdb/q9.rb +32 -0
- data/xquery_use_cases/rdb/q9.xquery +16 -0
- data/xquery_use_cases/rdb/users.xml +25 -0
- data/xquery_use_cases/seq/README +12 -0
- data/xquery_use_cases/seq/q1.out +1 -0
- data/xquery_use_cases/seq/q1.rb +25 -0
- data/xquery_use_cases/seq/q1.xquery +2 -0
- data/xquery_use_cases/seq/q2.out +2 -0
- data/xquery_use_cases/seq/q2.rb +25 -0
- data/xquery_use_cases/seq/q2.xquery +2 -0
- data/xquery_use_cases/seq/q3.out +2 -0
- data/xquery_use_cases/seq/q3.rb +26 -0
- data/xquery_use_cases/seq/q3.xquery +3 -0
- data/xquery_use_cases/seq/q4.out +0 -0
- data/xquery_use_cases/seq/q4.rb +27 -0
- data/xquery_use_cases/seq/q4.xquery +4 -0
- data/xquery_use_cases/seq/q5.out +5 -0
- data/xquery_use_cases/seq/q5.rb +29 -0
- data/xquery_use_cases/seq/q5.xquery +10 -0
- data/xquery_use_cases/seq/report1.xml +40 -0
- data/xquery_use_cases/sgml/README +53 -0
- data/xquery_use_cases/sgml/q1.out +44 -0
- data/xquery_use_cases/sgml/q1.rb +23 -0
- data/xquery_use_cases/sgml/q1.xquery +5 -0
- data/xquery_use_cases/sgml/q10.out +1 -0
- data/xquery_use_cases/sgml/q10.rb +28 -0
- data/xquery_use_cases/sgml/q10.xquery +7 -0
- data/xquery_use_cases/sgml/q2.out +26 -0
- data/xquery_use_cases/sgml/q2.rb +23 -0
- data/xquery_use_cases/sgml/q2.xquery +5 -0
- data/xquery_use_cases/sgml/q3.out +6 -0
- data/xquery_use_cases/sgml/q3.rb +28 -0
- data/xquery_use_cases/sgml/q3.xquery +7 -0
- data/xquery_use_cases/sgml/q4.out +4 -0
- data/xquery_use_cases/sgml/q4.rb +25 -0
- data/xquery_use_cases/sgml/q4.xquery +5 -0
- data/xquery_use_cases/sgml/q5.out +3 -0
- data/xquery_use_cases/sgml/q5.rb +23 -0
- data/xquery_use_cases/sgml/q5.xquery +5 -0
- data/xquery_use_cases/sgml/q6.out +1 -0
- data/xquery_use_cases/sgml/q6.rb +27 -0
- data/xquery_use_cases/sgml/q6.xquery +6 -0
- data/xquery_use_cases/sgml/q7.out +1 -0
- data/xquery_use_cases/sgml/q7.rb +27 -0
- data/xquery_use_cases/sgml/q7.xquery +7 -0
- data/xquery_use_cases/sgml/q8a.out +34 -0
- data/xquery_use_cases/sgml/q8a.rb +27 -0
- data/xquery_use_cases/sgml/q8a.xquery +5 -0
- data/xquery_use_cases/sgml/q8b.out +26 -0
- data/xquery_use_cases/sgml/q8b.rb +32 -0
- data/xquery_use_cases/sgml/q8b.xquery +5 -0
- data/xquery_use_cases/sgml/q9.out +9 -0
- data/xquery_use_cases/sgml/q9.rb +29 -0
- data/xquery_use_cases/sgml/q9.xquery +6 -0
- data/xquery_use_cases/sgml/sgml.xml +101 -0
- data/xquery_use_cases/solution_sizes.rb +48 -0
- data/xquery_use_cases/string/README +29 -0
- data/xquery_use_cases/string/company-data.xml +20 -0
- data/xquery_use_cases/string/q1.out +4 -0
- data/xquery_use_cases/string/q1.rb +25 -0
- data/xquery_use_cases/string/q1.xquery +1 -0
- data/xquery_use_cases/string/q2.out +13 -0
- data/xquery_use_cases/string/q2.rb +32 -0
- data/xquery_use_cases/string/q2.xquery +23 -0
- data/xquery_use_cases/string/q4.out +50 -0
- data/xquery_use_cases/string/q4.rb +34 -0
- data/xquery_use_cases/string/q4.xquery +14 -0
- data/xquery_use_cases/string/q5.out +12 -0
- data/xquery_use_cases/string/q5.rb +33 -0
- data/xquery_use_cases/string/q5.xquery +8 -0
- data/xquery_use_cases/string/string.xml +82 -0
- data/xquery_use_cases/test_driver.rb +60 -0
- data/xquery_use_cases/tree/README +23 -0
- data/xquery_use_cases/tree/book.xml +50 -0
- data/xquery_use_cases/tree/q1.out +23 -0
- data/xquery_use_cases/tree/q1.rb +31 -0
- data/xquery_use_cases/tree/q1.xquery +14 -0
- data/xquery_use_cases/tree/q2.out +11 -0
- data/xquery_use_cases/tree/q2.rb +27 -0
- data/xquery_use_cases/tree/q2.xquery +10 -0
- data/xquery_use_cases/tree/q3.out +2 -0
- data/xquery_use_cases/tree/q3.rb +26 -0
- data/xquery_use_cases/tree/q3.xquery +2 -0
- data/xquery_use_cases/tree/q4.out +1 -0
- data/xquery_use_cases/tree/q4.rb +23 -0
- data/xquery_use_cases/tree/q4.xquery +5 -0
- data/xquery_use_cases/tree/q5.out +9 -0
- data/xquery_use_cases/tree/q5.rb +30 -0
- data/xquery_use_cases/tree/q5.xquery +8 -0
- data/xquery_use_cases/tree/q6.out +30 -0
- data/xquery_use_cases/tree/q6.rb +35 -0
- data/xquery_use_cases/tree/q6.xquery +21 -0
- data/xquery_use_cases/xmp/README +41 -0
- data/xquery_use_cases/xmp/bib.xml +35 -0
- data/xquery_use_cases/xmp/books.xml +15 -0
- data/xquery_use_cases/xmp/prices.xml +32 -0
- data/xquery_use_cases/xmp/q1.out +8 -0
- data/xquery_use_cases/xmp/q1.rb +29 -0
- data/xquery_use_cases/xmp/q1.xquery +10 -0
- data/xquery_use_cases/xmp/q10.out +11 -0
- data/xquery_use_cases/xmp/q10.rb +36 -0
- data/xquery_use_cases/xmp/q10.xquery +11 -0
- data/xquery_use_cases/xmp/q11.out +35 -0
- data/xquery_use_cases/xmp/q11.rb +37 -0
- data/xquery_use_cases/xmp/q11.xquery +18 -0
- data/xquery_use_cases/xmp/q12.out +6 -0
- data/xquery_use_cases/xmp/q12.rb +35 -0
- data/xquery_use_cases/xmp/q12.xquery +20 -0
- data/xquery_use_cases/xmp/q2.out +37 -0
- data/xquery_use_cases/xmp/q2.rb +30 -0
- data/xquery_use_cases/xmp/q2.xquery +12 -0
- data/xquery_use_cases/xmp/q3.out +34 -0
- data/xquery_use_cases/xmp/q3.rb +27 -0
- data/xquery_use_cases/xmp/q3.xquery +10 -0
- data/xquery_use_cases/xmp/q4.out +31 -0
- data/xquery_use_cases/xmp/q4.rb +44 -0
- data/xquery_use_cases/xmp/q4.xquery +21 -0
- data/xquery_use_cases/xmp/q5.out +17 -0
- data/xquery_use_cases/xmp/q5.rb +38 -0
- data/xquery_use_cases/xmp/q5.xquery +13 -0
- data/xquery_use_cases/xmp/q6.out +28 -0
- data/xquery_use_cases/xmp/q6.rb +33 -0
- data/xquery_use_cases/xmp/q6.xquery +19 -0
- data/xquery_use_cases/xmp/q7.out +8 -0
- data/xquery_use_cases/xmp/q7.rb +30 -0
- data/xquery_use_cases/xmp/q7.xquery +12 -0
- data/xquery_use_cases/xmp/q8.out +7 -0
- data/xquery_use_cases/xmp/q8.rb +29 -0
- data/xquery_use_cases/xmp/q8.xquery +9 -0
- data/xquery_use_cases/xmp/q9.out +4 -0
- data/xquery_use_cases/xmp/q9.rb +29 -0
- data/xquery_use_cases/xmp/q9.xquery +7 -0
- data/xquery_use_cases/xmp/reviews.xml +24 -0
- metadata +342 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
W3C XML Query Use Cases contains the following use cases:
|
|
2
|
+
1. Use Case "XMP": Experiences and Exemplars
|
|
3
|
+
2. Use Case "TREE": Queries that preserve hierarchy
|
|
4
|
+
3. Use Case "SEQ" - Queries based on Sequence
|
|
5
|
+
4. Use Case "R" - Access to Relational Data
|
|
6
|
+
5. Use Case "SGML": Standard Generalized Markup Language
|
|
7
|
+
6. Use Case "STRING": String Search
|
|
8
|
+
7. Use Case "NS" - Queries Using Namespaces
|
|
9
|
+
8. Use Case "PARTS" - Recursive Parts Explosion
|
|
10
|
+
9. Use Case "STRONG" - queries that exploit strongly typed data
|
|
11
|
+
|
|
12
|
+
Use cases 7 and 9 are not supported as they would require
|
|
13
|
+
special support for XML namespaces and XML Schema,
|
|
14
|
+
both of which are outside of scope of magic/xml.
|
|
15
|
+
|
|
16
|
+
Of the rest 1, 2, 3, 4, 5, 6, 8 are coded.
|
|
17
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Use Case "PARTS" - Recursive Parts Explosion
|
|
2
|
+
from XML Query Use Cases.
|
|
3
|
+
|
|
4
|
+
http://www.w3.org/TR/xquery-use-cases/#parts
|
|
5
|
+
|
|
6
|
+
Q1 - Convert the sample document from "partlist"
|
|
7
|
+
format to "parttree" format (see DTD section
|
|
8
|
+
for definitions). In the result document,
|
|
9
|
+
part containment is represented by containment
|
|
10
|
+
of one <part> element inside another. Each part
|
|
11
|
+
that is not part of any other part should appear
|
|
12
|
+
as a separate top-level element in the output document.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
2
|
+
<partlist>
|
|
3
|
+
<part partid="0" name="car"/>
|
|
4
|
+
<part partid="1" partof="0" name="engine"/>
|
|
5
|
+
<part partid="2" partof="0" name="door"/>
|
|
6
|
+
<part partid="3" partof="1" name="piston"/>
|
|
7
|
+
<part partid="4" partof="2" name="window"/>
|
|
8
|
+
<part partid="5" partof="2" name="lock"/>
|
|
9
|
+
<part partid="10" name="skateboard"/>
|
|
10
|
+
<part partid="11" partof="10" name="board"/>
|
|
11
|
+
<part partid="12" partof="10" name="wheel"/>
|
|
12
|
+
<part partid="20" name="canoe"/>
|
|
13
|
+
</partlist>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<parttree>
|
|
2
|
+
<part partid="0" name="car">
|
|
3
|
+
<part partid="1" name="engine">
|
|
4
|
+
<part partid="3" name="piston"/>
|
|
5
|
+
</part>
|
|
6
|
+
<part partid="2" name="door">
|
|
7
|
+
<part partid="4" name="window"/>
|
|
8
|
+
<part partid="5" name="lock"/>
|
|
9
|
+
</part>
|
|
10
|
+
</part>
|
|
11
|
+
<part partid="10" name="skateboard">
|
|
12
|
+
<part partid="11" name="board"/>
|
|
13
|
+
<part partid="12" name="wheel"/>
|
|
14
|
+
</part>
|
|
15
|
+
<part partid="20" name="canoe"/>
|
|
16
|
+
</parttree>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/ruby -I../.. -rmagic_xml
|
|
2
|
+
#Copyright (c) 2006-2007 Tomasz Wegrzanowski <Tomasz.Wegrzanowski@gmail.com>
|
|
3
|
+
#
|
|
4
|
+
#Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
#copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
#to deal in the Software without restriction, including without limitation
|
|
7
|
+
#the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
#and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
#Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
#The above copyright notice and this permission notice shall be included in
|
|
12
|
+
#all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
17
|
+
#THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
18
|
+
#OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
#ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
#DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def parts_of(parts, partid)
|
|
24
|
+
res = []
|
|
25
|
+
parts.each{|p|
|
|
26
|
+
if p[:partof] == partid
|
|
27
|
+
a = p.attrs.dup
|
|
28
|
+
a.delete :partof
|
|
29
|
+
res << xml(:part, a, parts_of(parts, p[:partid]))
|
|
30
|
+
end
|
|
31
|
+
}
|
|
32
|
+
res
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
XML.parttree! {
|
|
36
|
+
parts = XML.load('partlist.xml').children(:part)
|
|
37
|
+
add! parts_of(parts, nil)
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare function local:one_level($p as element()) as element()
|
|
2
|
+
{
|
|
3
|
+
<part partid="{ $p/@partid }"
|
|
4
|
+
name="{ $p/@name }" >
|
|
5
|
+
{
|
|
6
|
+
for $s in doc("partlist.xml")//part
|
|
7
|
+
where $s/@partof = $p/@partid
|
|
8
|
+
return local:one_level($s)
|
|
9
|
+
}
|
|
10
|
+
</part>
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
<parttree>
|
|
14
|
+
{
|
|
15
|
+
for $p in doc("partlist.xml")//part[empty(@partof)]
|
|
16
|
+
return local:one_level($p)
|
|
17
|
+
}
|
|
18
|
+
</parttree>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from XML Query Use Cases.
|
|
2
|
+
|
|
3
|
+
Source: http://www.w3.org/TR/xquery-use-cases/#rdb
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Q1 - List the item number and description of all bicycles that
|
|
7
|
+
currently have an auction in progress, ordered by item number.
|
|
8
|
+
Q2 - For all bicycles, list the item number, description,
|
|
9
|
+
and highest bid (if any), ordered by item number.
|
|
10
|
+
Q3 - Find cases where a user with a rating worse
|
|
11
|
+
(alphabetically, greater) than "C" is offering an item
|
|
12
|
+
with a reserve price of more than 1000.
|
|
13
|
+
Q4 - List item numbers and descriptions of items that have no bids.
|
|
14
|
+
For bicycle(s) offered by Tom Jones that have received a bid,
|
|
15
|
+
list the item number, description, highest bid, and name
|
|
16
|
+
of the highest bidder, ordered by item number.
|
|
17
|
+
Q6 - For each item whose highest bid is more than twice its
|
|
18
|
+
reserve price, list the item number, description,
|
|
19
|
+
reserve price, and highest bid.
|
|
20
|
+
Q7 - Find the highest bid ever made for a bicycle or tricycle.
|
|
21
|
+
Q8 - How many items were actioned (auction ended) in March 1999?
|
|
22
|
+
Q9 - List the number of items auctioned each month in 1999 for
|
|
23
|
+
which data is available, ordered by month.
|
|
24
|
+
Q10 - For each item that has received a bid, list the item
|
|
25
|
+
number, the highest bid, and the name of the highest
|
|
26
|
+
bidder, ordered by item number.
|
|
27
|
+
Q11 - List the item number and description of the item(s)
|
|
28
|
+
that received the highest bid ever recorded, and the
|
|
29
|
+
amount of that bid.
|
|
30
|
+
Q12 - List the item number and description of the item(s)
|
|
31
|
+
that received the largest number of bids, and the
|
|
32
|
+
number of bids it (or they) received.
|
|
33
|
+
Q13 - For each user who has placed a bid, give the userid,
|
|
34
|
+
name, number of bids, and average bid, in order by userid.
|
|
35
|
+
Q14 - List item numbers and average bids for items that have
|
|
36
|
+
received three or more bids, in descending order by average bid.
|
|
37
|
+
Q15 - List names of users who have placed multiple bids of
|
|
38
|
+
at least $100 each.
|
|
39
|
+
Q16 - List all registered users in order by userid; for each user,
|
|
40
|
+
include the userid, name, and an indication of whether the
|
|
41
|
+
user is active (has at least one bid on record) or inactive
|
|
42
|
+
(has no bid on record).
|
|
43
|
+
Q17 - List the names of users, if any, who have bid on every item.
|
|
44
|
+
Q18 - List all users in alphabetic order by name. For each user,
|
|
45
|
+
include descriptions of all the items (if any) that were
|
|
46
|
+
bid on by that user, in alphabetic order.
|
|
47
|
+
|
|
48
|
+
Note to Q1: This solution assumes that the current date is 1999-01-31.
|
|
49
|
+
|
|
50
|
+
Note: many XQuery solutions have start_date/end_date vs. start_day/end_day bug
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<bids>
|
|
2
|
+
<bid_tuple>
|
|
3
|
+
<userid>U02</userid>
|
|
4
|
+
<itemno>1001</itemno>
|
|
5
|
+
<bid>35</bid>
|
|
6
|
+
<bid_date>1999-01-07</bid_date></bid_tuple>
|
|
7
|
+
<bid_tuple>
|
|
8
|
+
<userid>U04</userid>
|
|
9
|
+
<itemno>1001</itemno>
|
|
10
|
+
<bid>40</bid>
|
|
11
|
+
<bid_date>1999-01-08</bid_date></bid_tuple>
|
|
12
|
+
<bid_tuple>
|
|
13
|
+
<userid>U02</userid>
|
|
14
|
+
<itemno>1001</itemno>
|
|
15
|
+
<bid>45</bid>
|
|
16
|
+
<bid_date>1999-01-11</bid_date></bid_tuple>
|
|
17
|
+
<bid_tuple>
|
|
18
|
+
<userid>U04</userid>
|
|
19
|
+
<itemno>1001</itemno>
|
|
20
|
+
<bid>50</bid>
|
|
21
|
+
<bid_date>1999-01-13</bid_date></bid_tuple>
|
|
22
|
+
<bid_tuple>
|
|
23
|
+
<userid>U02</userid>
|
|
24
|
+
<itemno>1001</itemno>
|
|
25
|
+
<bid>55</bid>
|
|
26
|
+
<bid_date>1999-01-15</bid_date></bid_tuple>
|
|
27
|
+
<bid_tuple>
|
|
28
|
+
<userid>U01</userid>
|
|
29
|
+
<itemno>1002</itemno>
|
|
30
|
+
<bid>400</bid>
|
|
31
|
+
<bid_date>1999-02-14</bid_date></bid_tuple>
|
|
32
|
+
<bid_tuple>
|
|
33
|
+
<userid>U02</userid>
|
|
34
|
+
<itemno>1002</itemno>
|
|
35
|
+
<bid>600</bid>
|
|
36
|
+
<bid_date>1999-02-16</bid_date></bid_tuple>
|
|
37
|
+
<bid_tuple>
|
|
38
|
+
<userid>U03</userid>
|
|
39
|
+
<itemno>1002</itemno>
|
|
40
|
+
<bid>800</bid>
|
|
41
|
+
<bid_date>1999-02-17</bid_date></bid_tuple>
|
|
42
|
+
<bid_tuple>
|
|
43
|
+
<userid>U04</userid>
|
|
44
|
+
<itemno>1002</itemno>
|
|
45
|
+
<bid>1000</bid>
|
|
46
|
+
<bid_date>1999-02-25</bid_date></bid_tuple>
|
|
47
|
+
<bid_tuple>
|
|
48
|
+
<userid>U02</userid>
|
|
49
|
+
<itemno>1002</itemno>
|
|
50
|
+
<bid>1200</bid>
|
|
51
|
+
<bid_date>1999-03-02</bid_date></bid_tuple>
|
|
52
|
+
<bid_tuple>
|
|
53
|
+
<userid>U04</userid>
|
|
54
|
+
<itemno>1003</itemno>
|
|
55
|
+
<bid>15</bid>
|
|
56
|
+
<bid_date>1999-01-22</bid_date></bid_tuple>
|
|
57
|
+
<bid_tuple>
|
|
58
|
+
<userid>U05</userid>
|
|
59
|
+
<itemno>1003</itemno>
|
|
60
|
+
<bid>20</bid>
|
|
61
|
+
<bid_date>1999-02-03</bid_date></bid_tuple>
|
|
62
|
+
<bid_tuple>
|
|
63
|
+
<userid>U01</userid>
|
|
64
|
+
<itemno>1004</itemno>
|
|
65
|
+
<bid>40</bid>
|
|
66
|
+
<bid_date>1999-03-05</bid_date></bid_tuple>
|
|
67
|
+
<bid_tuple>
|
|
68
|
+
<userid>U03</userid>
|
|
69
|
+
<itemno>1007</itemno>
|
|
70
|
+
<bid>175</bid>
|
|
71
|
+
<bid_date>1999-01-25</bid_date></bid_tuple>
|
|
72
|
+
<bid_tuple>
|
|
73
|
+
<userid>U05</userid>
|
|
74
|
+
<itemno>1007</itemno>
|
|
75
|
+
<bid>200</bid>
|
|
76
|
+
<bid_date>1999-02-08</bid_date></bid_tuple>
|
|
77
|
+
<bid_tuple>
|
|
78
|
+
<userid>U04</userid>
|
|
79
|
+
<itemno>1007</itemno>
|
|
80
|
+
<bid>225</bid>
|
|
81
|
+
<bid_date>1999-02-12</bid_date></bid_tuple></bids>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<items>
|
|
2
|
+
<item_tuple>
|
|
3
|
+
<itemno>1001</itemno>
|
|
4
|
+
<description>Red Bicycle</description>
|
|
5
|
+
<offered_by>U01</offered_by>
|
|
6
|
+
<start_day>1999-01-05</start_day>
|
|
7
|
+
<end_day>1999-01-20</end_day>
|
|
8
|
+
<reserve_price>40</reserve_price></item_tuple>
|
|
9
|
+
<item_tuple>
|
|
10
|
+
<itemno>1002</itemno>
|
|
11
|
+
<description>Motorcycle</description>
|
|
12
|
+
<offered_by>U02</offered_by>
|
|
13
|
+
<start_day>1999-02-11</start_day>
|
|
14
|
+
<end_day>1999-03-15</end_day>
|
|
15
|
+
<reserve_price>500</reserve_price></item_tuple>
|
|
16
|
+
<item_tuple>
|
|
17
|
+
<itemno>1003</itemno>
|
|
18
|
+
<description>Old Bicycle</description>
|
|
19
|
+
<offered_by>U02</offered_by>
|
|
20
|
+
<start_day>1999-01-10</start_day>
|
|
21
|
+
<end_day>1999-02-20</end_day>
|
|
22
|
+
<reserve_price>25</reserve_price></item_tuple>
|
|
23
|
+
<item_tuple>
|
|
24
|
+
<itemno>1004</itemno>
|
|
25
|
+
<description>Tricycle</description>
|
|
26
|
+
<offered_by>U01</offered_by>
|
|
27
|
+
<start_day>1999-02-25</start_day>
|
|
28
|
+
<end_day>1999-03-08</end_day>
|
|
29
|
+
<reserve_price>15</reserve_price></item_tuple>
|
|
30
|
+
<item_tuple>
|
|
31
|
+
<itemno>1005</itemno>
|
|
32
|
+
<description>Tennis Racket</description>
|
|
33
|
+
<offered_by>U03</offered_by>
|
|
34
|
+
<start_day>1999-03-19</start_day>
|
|
35
|
+
<end_day>1999-04-30</end_day>
|
|
36
|
+
<reserve_price>20</reserve_price></item_tuple>
|
|
37
|
+
<item_tuple>
|
|
38
|
+
<itemno>1006</itemno>
|
|
39
|
+
<description>Helicopter</description>
|
|
40
|
+
<offered_by>U03</offered_by>
|
|
41
|
+
<start_day>1999-05-05</start_day>
|
|
42
|
+
<end_day>1999-05-25</end_day>
|
|
43
|
+
<reserve_price>50000</reserve_price></item_tuple>
|
|
44
|
+
<item_tuple>
|
|
45
|
+
<itemno>1007</itemno>
|
|
46
|
+
<description>Racing Bicycle</description>
|
|
47
|
+
<offered_by>U04</offered_by>
|
|
48
|
+
<start_day>1999-01-20</start_day>
|
|
49
|
+
<end_day>1999-02-20</end_day>
|
|
50
|
+
<reserve_price>200</reserve_price></item_tuple>
|
|
51
|
+
<item_tuple>
|
|
52
|
+
<itemno>1008</itemno>
|
|
53
|
+
<description>Broken Bicycle</description>
|
|
54
|
+
<offered_by>U01</offered_by>
|
|
55
|
+
<start_day>1999-02-05</start_day>
|
|
56
|
+
<end_day>1999-03-06</end_day>
|
|
57
|
+
<reserve_price>25</reserve_price></item_tuple></items>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/ruby -I../.. -rmagic_xml
|
|
2
|
+
#Copyright (c) 2006-2007 Tomasz Wegrzanowski <Tomasz.Wegrzanowski@gmail.com>
|
|
3
|
+
#
|
|
4
|
+
#Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
#copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
#to deal in the Software without restriction, including without limitation
|
|
7
|
+
#the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
#and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
#Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
#The above copyright notice and this permission notice shall be included in
|
|
12
|
+
#all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
17
|
+
#THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
18
|
+
#OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
#ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
#DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
current_day = "1999-01-31"
|
|
24
|
+
|
|
25
|
+
items = XML.load('items.xml').sort_by{|i| i[:@itemno].to_i}
|
|
26
|
+
XML.result! {
|
|
27
|
+
items.each(XML) {|i|
|
|
28
|
+
next unless current_day.between?(i[:@start_day], i[:@end_day]) and i[:@description] =~ /Bicycle/
|
|
29
|
+
item_tuple!(i.children(:itemno), i.children(:description))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<result>
|
|
2
|
+
{
|
|
3
|
+
for $i in doc("items.xml")//item_tuple
|
|
4
|
+
where $i/start_date <= current-date()
|
|
5
|
+
and $i/end_date >= current-date()
|
|
6
|
+
and contains($i/description, "Bicycle")
|
|
7
|
+
order by $i/itemno
|
|
8
|
+
return
|
|
9
|
+
<item_tuple>
|
|
10
|
+
{ $i/itemno }
|
|
11
|
+
{ $i/description }
|
|
12
|
+
</item_tuple>
|
|
13
|
+
}
|
|
14
|
+
</result>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<result>
|
|
2
|
+
<high_bid>
|
|
3
|
+
<itemno>1001</itemno>
|
|
4
|
+
<bid>55</bid>
|
|
5
|
+
<bidder>Mary Doe</bidder>
|
|
6
|
+
</high_bid>
|
|
7
|
+
<high_bid>
|
|
8
|
+
<itemno>1002</itemno>
|
|
9
|
+
<bid>1200</bid>
|
|
10
|
+
<bidder>Mary Doe</bidder>
|
|
11
|
+
</high_bid>
|
|
12
|
+
<high_bid>
|
|
13
|
+
<itemno>1003</itemno>
|
|
14
|
+
<bid>20</bid>
|
|
15
|
+
<bidder>Jack Sprat</bidder>
|
|
16
|
+
</high_bid>
|
|
17
|
+
<high_bid>
|
|
18
|
+
<itemno>1004</itemno>
|
|
19
|
+
<bid>40</bid>
|
|
20
|
+
<bidder>Tom Jones</bidder>
|
|
21
|
+
</high_bid>
|
|
22
|
+
<high_bid>
|
|
23
|
+
<itemno>1007</itemno>
|
|
24
|
+
<bid>225</bid>
|
|
25
|
+
<bidder>Roger Smith</bidder>
|
|
26
|
+
</high_bid>
|
|
27
|
+
</result>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/ruby -I../.. -rmagic_xml
|
|
2
|
+
#Copyright (c) 2006-2007 Tomasz Wegrzanowski <Tomasz.Wegrzanowski@gmail.com>
|
|
3
|
+
#
|
|
4
|
+
#Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
#copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
#to deal in the Software without restriction, including without limitation
|
|
7
|
+
#the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
#and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
#Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
#The above copyright notice and this permission notice shall be included in
|
|
12
|
+
#all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
17
|
+
#THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
18
|
+
#OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
#ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
#DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
users = XML.load('users.xml')
|
|
24
|
+
bids = XML.load('bids.xml').sort_by{|b| b[:@itemno].to_i}
|
|
25
|
+
|
|
26
|
+
XML.result! {
|
|
27
|
+
bids.each{|highbid|
|
|
28
|
+
next if bids.any?{|b| b[:@itemno] == highbid[:@itemno] and b[:@bid].to_i > highbid[:@bid].to_i}
|
|
29
|
+
users.children({:@userid => highbid[:@userid]}){|user|
|
|
30
|
+
high_bid! {
|
|
31
|
+
add! highbid.child(:itemno)
|
|
32
|
+
add! highbid.child(:bid)
|
|
33
|
+
bidder! user[:@name]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<result>
|
|
2
|
+
{
|
|
3
|
+
for $highbid in doc("bids.xml")//bid_tuple,
|
|
4
|
+
$user in doc("users.xml")//user_tuple
|
|
5
|
+
where $user/userid = $highbid/userid
|
|
6
|
+
and $highbid/bid = max(doc("bids.xml")//bid_tuple[itemno=$highbid/itemno]/bid)
|
|
7
|
+
order by $highbid/itemno
|
|
8
|
+
return
|
|
9
|
+
<high_bid>
|
|
10
|
+
{ $highbid/itemno }
|
|
11
|
+
{ $highbid/bid }
|
|
12
|
+
<bidder>{ $user/name/text() }</bidder>
|
|
13
|
+
</high_bid>
|
|
14
|
+
}
|
|
15
|
+
</result>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/ruby -I../.. -rmagic_xml
|
|
2
|
+
#Copyright (c) 2006-2007 Tomasz Wegrzanowski <Tomasz.Wegrzanowski@gmail.com>
|
|
3
|
+
#
|
|
4
|
+
#Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
#copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
#to deal in the Software without restriction, including without limitation
|
|
7
|
+
#the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
#and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
#Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
#The above copyright notice and this permission notice shall be included in
|
|
12
|
+
#all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
17
|
+
#THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
18
|
+
#OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
#ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
#DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
items = XML.load('items.xml')
|
|
24
|
+
bids = XML.load('bids.xml')
|
|
25
|
+
|
|
26
|
+
highbid = bids.children.children(:bid).map{|b| b.text.to_i}.max.to_s
|
|
27
|
+
|
|
28
|
+
XML.result! {
|
|
29
|
+
items.each(XML){|item|
|
|
30
|
+
bids.each({:@itemno => item[:@itemno], :@bid => highbid}) {|b|
|
|
31
|
+
expensive_item! {
|
|
32
|
+
add! item.child(:itemno)
|
|
33
|
+
add! item.child(:description)
|
|
34
|
+
high_bid! highbid
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let $highbid := max(doc("bids.xml")//bid_tuple/bid)
|
|
2
|
+
return
|
|
3
|
+
<result>
|
|
4
|
+
{
|
|
5
|
+
for $item in doc("items.xml")//item_tuple,
|
|
6
|
+
$b in doc("bids.xml")//bid_tuple[itemno = $item/itemno]
|
|
7
|
+
where $b/bid = $highbid
|
|
8
|
+
return
|
|
9
|
+
<expensive_item>
|
|
10
|
+
{ $item/itemno }
|
|
11
|
+
{ $item/description }
|
|
12
|
+
<high_bid>{ $highbid }</high_bid>
|
|
13
|
+
</expensive_item>
|
|
14
|
+
}
|
|
15
|
+
</result>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<result>
|
|
2
|
+
<popular_item>
|
|
3
|
+
<itemno>1001</itemno>
|
|
4
|
+
<description>Red Bicycle</description>
|
|
5
|
+
<bid_count>5</bid_count>
|
|
6
|
+
</popular_item>
|
|
7
|
+
<popular_item>
|
|
8
|
+
<itemno>1002</itemno>
|
|
9
|
+
<description>Motorcycle</description>
|
|
10
|
+
<bid_count>5</bid_count>
|
|
11
|
+
</popular_item>
|
|
12
|
+
</result>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/ruby -I../.. -rmagic_xml
|
|
2
|
+
#Copyright (c) 2006-2007 Tomasz Wegrzanowski <Tomasz.Wegrzanowski@gmail.com>
|
|
3
|
+
#
|
|
4
|
+
#Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
#copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
#to deal in the Software without restriction, including without limitation
|
|
7
|
+
#the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
#and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
#Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
#The above copyright notice and this permission notice shall be included in
|
|
12
|
+
#all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
17
|
+
#THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
18
|
+
#OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
#ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
#DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
items = XML.load('items.xml')
|
|
24
|
+
bids = XML.load('bids.xml').children(:bid_tuple)
|
|
25
|
+
|
|
26
|
+
# XML should work as a Hash key !
|
|
27
|
+
XML.result! {
|
|
28
|
+
bids_per_item = Hash.new([])
|
|
29
|
+
bids.each{|bid|
|
|
30
|
+
bids_per_item[bid[:@itemno]] += [bid]
|
|
31
|
+
}
|
|
32
|
+
max_bid_count = bids_per_item.map{|k,v| v.size}.max
|
|
33
|
+
|
|
34
|
+
items.each(XML){|item|
|
|
35
|
+
next unless bids_per_item[item[:@itemno]].size == max_bid_count
|
|
36
|
+
popular_item! {
|
|
37
|
+
add! item.child(:itemno)
|
|
38
|
+
add! item.child(:description)
|
|
39
|
+
bid_count! max_bid_count
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare function local:bid_summary()
|
|
2
|
+
as element()*
|
|
3
|
+
{
|
|
4
|
+
for $i in distinct-values(doc("bids.xml")//itemno)
|
|
5
|
+
let $b := doc("bids.xml")//bid_tuple[itemno = $i]
|
|
6
|
+
return
|
|
7
|
+
<bid_count>
|
|
8
|
+
<itemno>{ $i }</itemno>
|
|
9
|
+
<nbids>{ count($b) }</nbids>
|
|
10
|
+
</bid_count>
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
<result>
|
|
14
|
+
{
|
|
15
|
+
let $bid_counts := local:bid_summary(),
|
|
16
|
+
$maxbids := max($bid_counts/nbids),
|
|
17
|
+
$maxitemnos := $bid_counts[nbids = $maxbids]
|
|
18
|
+
for $item in doc("items.xml")//item_tuple,
|
|
19
|
+
$bc in $bid_counts
|
|
20
|
+
where $bc/nbids = $maxbids and $item/itemno = $bc/itemno
|
|
21
|
+
return
|
|
22
|
+
<popular_item>
|
|
23
|
+
{ $item/itemno }
|
|
24
|
+
{ $item/description }
|
|
25
|
+
<bid_count>{ $bc/nbids/text() }</bid_count>
|
|
26
|
+
</popular_item>
|
|
27
|
+
}
|
|
28
|
+
</result>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<result>
|
|
2
|
+
<bidder>
|
|
3
|
+
<userid>U01</userid>
|
|
4
|
+
<name>Tom Jones</name>
|
|
5
|
+
<bidcount>2</bidcount>
|
|
6
|
+
<avgbid>220</avgbid>
|
|
7
|
+
</bidder>
|
|
8
|
+
<bidder>
|
|
9
|
+
<userid>U02</userid>
|
|
10
|
+
<name>Mary Doe</name>
|
|
11
|
+
<bidcount>5</bidcount>
|
|
12
|
+
<avgbid>387</avgbid>
|
|
13
|
+
</bidder>
|
|
14
|
+
<bidder>
|
|
15
|
+
<userid>U03</userid>
|
|
16
|
+
<name>Dee Linquent</name>
|
|
17
|
+
<bidcount>2</bidcount>
|
|
18
|
+
<avgbid>487.5</avgbid>
|
|
19
|
+
</bidder>
|
|
20
|
+
<bidder>
|
|
21
|
+
<userid>U04</userid>
|
|
22
|
+
<name>Roger Smith</name>
|
|
23
|
+
<bidcount>5</bidcount>
|
|
24
|
+
<avgbid>266</avgbid>
|
|
25
|
+
</bidder>
|
|
26
|
+
<bidder>
|
|
27
|
+
<userid>U05</userid>
|
|
28
|
+
<name>Jack Sprat</name>
|
|
29
|
+
<bidcount>2</bidcount>
|
|
30
|
+
<avgbid>110</avgbid>
|
|
31
|
+
</bidder>
|
|
32
|
+
</result>
|