Project

Profile

Help

Revision a31dd97a

Added by Norman Tovey-Walsh 8 months ago

Attempting to get samples working

View differences:

.gitignore
5 5
/.idea/
6 6
/src/test/testdata/temp/
7 7
/src/test/testdata/sandpit/
8
.DS_Store
8 9

  
9 10
# Auto-generated sources
10 11
/src/main/java/net/sf/saxon/lib/Feature.java
build.gradle
31 31
  asmDotNet.extendsFrom(implementation)
32 32
  documentation.extendsFrom(implementation)
33 33
  jeldoclet.extendsFrom(implementation)
34
  samples.extendsFrom(implementation)
34 35
}
35 36

  
36 37
// Set saxonLicenseDir in gradle.properties, or from the
......
124 125
    // I don't really understand why this has to be done explicitly...
125 126
    files("${System.getProperty('java.home')}/../lib/tools.jar")
126 127
  )
128
  samples (
129
    [group: 'javax.servlet', name: 'servlet-api', version: '2.5']
130
  )
127 131
}
128 132

  
129 133
javadoc {
......
274 278
apply from: "build-n.gradle"
275 279
apply from: "build-c.gradle"
276 280
apply from: "build-doc.gradle"
281
apply from: "test-suites.gradle"
277 282

  
278 283
def pathExists(pathname) {
279 284
  // Returns true iff pathame is an existing file or directory
......
576 581

  
577 582
// ============================================================
578 583

  
579
task hej_sampleConfig(
580
  type: JavaExec,
581
  description: "Construct the configuration file XSD"
582
) {
583
  inputs.files fileTree(dir: "${projectDir}/tools/featureKeys")
584
  inputs.files "${projectDir}/src/samples/config/config-raw.xsd"
585
  outputs.file "${projectDir}/src/samples/config/config.xsd"
586
  classpath = configurations.preprocessor
587
  main = "net.sf.saxon.Transform"
588
  args "${projectDir}/tools/featureKeys/FeatureKeys.xml",
589
    "-xsl:${projectDir}/tools/featureKeys/FeatureKeysToSchema.xsl",
590
    "-o:${projectDir}/src/samples/config/config.xsd",
591
    "FeatureKeys=FeatureKeys.xml",
592
    "AdditionalFeatures=AdditionalFeatures.xml",
593
    "ConfigSchema=${projectDir}/src/samples/config/config-raw.xsd"
594
}
595

  
596
// There's no real dependency here, but I'm not sure how the
597
// samples directory should be integrated into the build.
598 584
task hej_featureKeys(
599 585
  type: JavaExec,
600
  dependsOn: ["hej_sampleConfig"],
601 586
  description: "Construct the feature keys for HE"
602 587
) {
603 588
  inputs.files fileTree(dir: "${projectDir}/tools/featureKeys")
src/samples/java/ee/PullExamples.java
32 32
import java.io.*;
33 33
import java.util.Properties;
34 34

  
35
import static net.sf.saxon.pull.PullProvider.Event.START_ELEMENT;
36

  
35 37
/**
36 38
 * This class contains some examples of how to use the Pull interfaces
37 39
 * in Saxon.
......
171 173
    public void removePriceElements(PullProvider in, OutputStream out) throws XPathException {
172 174
        final NodeName priceElement = new NoNamespaceName("PRICE");
173 175
        PullFilter filter = new PullFilter(in) {
174
            public int next() throws XPathException {
176
            public Event next() throws XPathException {
175 177
                currentEvent = super.next();
176 178
                if (currentEvent == START_ELEMENT && getNodeName().equals(priceElement)) {
177 179
                    super.skipToMatchingEnd();
......
193 195
        double total = 0;
194 196
        int count = 0;
195 197
        while (true) {
196
            int event = in.next();
197
            if (event == PullProvider.END_OF_INPUT) {
198
            PullProvider.Event event = in.next();
199
            if (event == PullProvider.Event.END_OF_INPUT) {
198 200
                break;
199 201
            }
200
            if (event == PullProvider.START_ELEMENT && in.getNodeName().equals(priceElement)) {
202
            if (event == PullProvider.Event.START_ELEMENT && in.getNodeName().equals(priceElement)) {
201 203
                double value = config.getConversionRules().getStringToDoubleConverter().stringToNumber(in.getStringValue());
202 204
                total += value;
203 205
                count++;
src/samples/java/ee/XMarkBenchmark.java
121 121
            Configuration config = (saproduct ? new EnterpriseConfiguration() : new Configuration());
122 122
            if (satests) {
123 123
                config.setSchemaValidationMode(Validation.STRICT);
124
                /* ndw
124 125
                config.addSchemaSource(new StreamSource(new File(dir + "schema.xsd")),
125 126
                        config.getErrorListener());
127

  
128
                 */
129
                config.addSchemaSource(new StreamSource(new File(dir + "schema.xsd")));
130
                /* /ndw */
126 131
                config.setConfigurationProperty(Feature.USE_TYPED_VALUE_CACHE, false);
127 132
            }
128 133
            if (val) {
src/samples/java/he/QueryAPIExamples.java
270 270

  
271 271
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
272 272
        final SequenceIterator iter = exp.iterator(dynamicContext);
273
        final DocumentInfo doc = QueryResult.wrap(iter, config);
273
        final NodeInfo doc = QueryResult.wrap(iter, config);
274 274
        QueryResult.serialize(doc, new StreamResult(System.out), props);
275 275
    }
276 276

  
src/use-cases/ns/addq1.xq
1
xquery version "1.0";
2

  
3
(: Additional use case to demonstrate inline namespace declarations :)
4

  
5
<addQ1 xmlns:music="http://www.example.org/music/records">
6
  {
7
    //music:title
8
  }
9
</addQ1>
src/use-cases/ns/addq2.xq
1
xquery version "1.0";
2

  
3
(: Additional use case to demonstrate use of default element namespace :)
4

  
5
declare default element namespace "http://www.example.com/AuctionWatch";
6

  
7
<Q7>
8
  {
9
    for $a in //Auction
10
    return
11
        <a seller="{$a/Trading_Partners/Seller/*:ID}"
12
           buyer="{$a/Trading_Partners/High_Bidder/*:ID}"
13
           />
14
  }
15
</Q7>
src/use-cases/ns/auction.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<ma:AuctionWatchList
4
    xmlns:ma="http://www.example.com/AuctionWatch"
5
    xmlns:xlink="http://www.w3.org/1999/xlink"
6
    xmlns:anyzone="http://www.example.com/auctioneers#anyzone"
7
    xmlns:eachbay="http://www.example.com/auctioneers#eachbay"
8
    xmlns:yabadoo="http://www.example.com/auctioneers#yabadoo"
9
>
10

  
11
<!-- ________________________________________________________________________________ -->
12

  
13
<ma:Auction anyzone:ID="0321K372910">
14

  
15
    <ma:AuctionHomepage
16
        xlink:type="simple"
17
        xlink:href="http://www.example.com/item/0321K372910"
18
    />
19

  
20
    <ma:Schedule>
21
        <ma:Open    xmlns:dt="http://www.w3.org/2001/XMLSchema"
22
                dt:type="timeInstant">2000-03-21:07:41:34-05:00</ma:Open>
23
        <ma:Close    xmlns:dt="http://www.w3.org/2001/XMLSchema"
24
                dt:type="timeInstant">2000-03-23:07:41:34-05:00</ma:Close>
25
    </ma:Schedule>
26
    
27
    <ma:Price>
28
        <ma:Start ma:currency="USD">3.00</ma:Start>
29
        <ma:Current ma:currency="USD">10.00</ma:Current>
30
        <ma:Number_of_Bids>5</ma:Number_of_Bids>
31
    </ma:Price>
32

  
33
    <ma:Trading_Partners>
34
        <ma:High_Bidder>
35
            <eachbay:ID>RecordsRUs</eachbay:ID>
36
            <eachbay:PositiveComments>231</eachbay:PositiveComments>
37
            <eachbay:NeutralComments>2</eachbay:NeutralComments>
38
            <eachbay:NegativeComments>5</eachbay:NegativeComments>
39
            <ma:MemberInfoPage
40
                xlink:type="simple"
41
                xlink:href="http://auction.eachbay.com/members?get=RecordsRUs"
42
                xlink:role="ma:MemberInfoPage"
43
            />            
44
        </ma:High_Bidder>
45
        <ma:Seller>
46
            <anyzone:ID>VintageRecordFreak</anyzone:ID>
47
            <anyzone:Member_Since>October 1999</anyzone:Member_Since>
48
            <anyzone:Rating>5</anyzone:Rating>
49
            <ma:MemberInfoPage
50
               xlink:type="simple"
51
               xlink:href="http://auction.anyzone.com/members/VintageRecordFreak"
52
               xlink:role="ma:MemberInfoPage"
53
            />
54
        </ma:Seller>
55
    </ma:Trading_Partners>
56

  
57
    <ma:Details>
58
        <record xmlns="http://www.example.org/music/records">
59
            <artist>Miles Davis</artist>
60
            <title>In a Silent Way</title>
61
            <recorded>1969</recorded>
62
            <label>Columbia Records</label>
63

  
64
            <remark>
65
                With Miles Davis (trumpet), Herbie Hancock (Electric
66
                Piano), Chick Corea (Electric Piano), Wayne Shorter
67
                (Tenor Sax), Josef Zawinul (Electric Piano &amp;
68
                Organ), John McLaughlin (Guitar), and Tony Williams
69
                (Drums).  The liner notes were written by Frank Glenn,
70
                and the record is in fine condition.
71
            </remark>
72

  
73
        </record>
74
    </ma:Details>
75

  
76
</ma:Auction>
77

  
78
<!-- ________________________________________________________________________________ -->
79

  
80

  
81
<ma:Auction yabadoo:ID="13143816">
82

  
83
    <ma:AuctionHomepage
84
        xlink:type="simple"
85
        xlink:href="http://auctions.yabadoo.com/auction/13143816"
86
    />
87

  
88
    <ma:Schedule>
89
        <ma:Open    xmlns:dt="http://www.w3.org/2001/XMLSchema"
90
                dt:type="timeInstant">2000-03-19:17:03:00-04:00</ma:Open>
91
        <ma:Close    xmlns:dt="http://www.w3.org/2001/XMLSchema"
92
                dt:type="timeInstant">2000-03-29:17:03:00-04:00</ma:Close>
93
    </ma:Schedule>
94
    
95
    <ma:Price>
96
        <ma:Start ma:currency="USD">3.00</ma:Start>
97
        <ma:Current ma:currency="USD">3.00</ma:Current>
98
        <ma:Number_of_Bids>0</ma:Number_of_Bids>
99
    </ma:Price>
100

  
101
    <ma:Trading_Partners>
102
        <ma:High_Bidder>
103
            <eachbay:ID>VintageRecordFreak</eachbay:ID>
104
            <eachbay:PositiveComments>232</eachbay:PositiveComments>
105
            <eachbay:NeutralComments>0</eachbay:NeutralComments>
106
            <eachbay:NegativeComments>0</eachbay:NegativeComments>
107
            <ma:MemberInfoPage
108
                xlink:type="simple"
109
                xlink:href="http://auction.eachbay.com/showRating/user=VintageRecordFreak"
110
                xlink:role="ma:MemberInfoPage"
111
            />            
112
        </ma:High_Bidder>
113
        <ma:Seller xmlns:seller="http://www.example.com/auctioneers#eachbay">
114
            <seller:ID>StarsOn45</seller:ID>
115
            <seller:PositiveComments>80</seller:PositiveComments>
116
            <seller:NeutralComments>1</seller:NeutralComments>
117
            <seller:NegativeComments>2</seller:NegativeComments>
118
            <ma:MemberInfoPage
119
                xlink:type="simple"
120
                xlink:href="http://auction.eachbay.com/showRating/user=StarsOn45"
121
                xlink:role="ma:MemberInfoPage"
122
            />            
123
        </ma:Seller>
124
    </ma:Trading_Partners>
125

  
126
    <ma:Details>
127
        <record xmlns="http://www.example.org/music/records">
128
            <artist>Wynton Marsalis</artist>
129
            <title>Think of One ...</title>
130
            <recorded>1983</recorded>
131
            <label>Columbia Records</label>
132
            <remark xml:lang="en"> Columbia Records 12" 33-1/3 rpm LP,
133
                #FC-38641, Stereo. The record is still clean and shiny
134
                and looks unplayed (looks like NM condition).  The
135
                cover has very light surface and edge wear.
136
            </remark>
137
            <remark xml:lang="de"> Columbia Records 12" 33-1/3 rpm LP,
138
                #FC-38641, Stereo. Die Platte ist noch immer sauber
139
                und gl?nzend und sieht ungespielt aus
140
                (NM Zustand). Das Cover hat leichte Abnutzungen an
141
                Oberfl?che und Ecken.
142
            </remark>
143
        </record>
144
    </ma:Details>
145

  
146
</ma:Auction>         
147

  
148
</ma:AuctionWatchList>
src/use-cases/ns/q1.out
1
<Q1>
2
  <ns>http://www.example.com/AuctionWatch</ns>
3
  <ns>http://www.example.com/auctioneers#anyzone</ns>
4
  <ns>http://www.w3.org/1999/xlink</ns>
5
  <ns>http://www.w3.org/2001/XMLSchema</ns>
6
  <ns>http://www.example.com/auctioneers#eachbay</ns>
7
  <ns>http://www.example.org/music/records</ns>
8
  <ns>http://www.example.com/auctioneers#yabadoo</ns>
9
  <ns>xml</ns>
10
</Q1>
src/use-cases/ns/q1.xq
1
<Q1>
2
  {
3
    for $n in distinct-values(
4
                  for $i in (//* | //@*)
5
                  return namespace-uri($i) 
6
               )
7
    return  <ns>{$n}</ns>
8
  }
9
</Q1>
src/use-cases/ns/q2.out
1
<Q2 xmlns:music="http://www.example.org/music/records">
2
  <music:title>In a Silent Way</music:title>
3
  <music:title>Think of One ...</music:title>
4
</Q2>
src/use-cases/ns/q2.xq
1
declare namespace music = "http://www.example.org/music/records";
2

  
3
<Q2>
4
  {
5
    //music:title
6
  }
7
</Q2>
src/use-cases/ns/q3.out
1
<Q3 xmlns:dt="http://www.w3.org/2001/XMLSchema">
2
  <ma:Open xmlns:ma="http://www.example.com/AuctionWatch" 
3
           dt:type="timeInstant">2000-03-21:07:41:34-05:00</ma:Open>
4
  <ma:Close xmlns:ma="http://www.example.com/AuctionWatch" 
5
           dt:type="timeInstant">2000-03-23:07:41:34-05:00</ma:Close>
6
  <ma:Open xmlns:ma="http://www.example.com/AuctionWatch" 
7
           dt:type="timeInstant">2000-03-19:17:03:00-04:00</ma:Open>
8
  <ma:Close xmlns:ma="http://www.example.com/AuctionWatch" 
9
           dt:type="timeInstant">2000-03-29:17:03:00-04:00</ma:Close>
10
</Q3>
src/use-cases/ns/q3.xq
1
declare namespace dt = "http://www.w3.org/2001/XMLSchema";
2

  
3
<Q3>
4
  {
5
    //*[@dt:*]
6
  }
7
</Q3>
src/use-cases/ns/q4.out
1
<Q4 xmlns:xlink="http://www.w3.org/1999/xlink">
2
  <ns xlink:href="http://www.example.com/item/0321K372910"/>
3
  <ns xlink:href="http://auction.eachbay.com/members?get=RecordsRUs"/>
4
  <ns xlink:href="http://auction.anyzone.com/members/VintageRecordFreak"/>
5
  <ns xlink:href="http://auctions.yabadoo.com/auction/13143816"/>
6
  <ns xlink:href="http://auction.eachbay.com/showRating/user=VintageRecordFreak"/>
7
  <ns xlink:href="http://auction.eachbay.com/showRating/user=StarsOn45"/>
8
</Q4>
src/use-cases/ns/q4.xq
1
declare namespace xlink = "http://www.w3.org/1999/xlink";
2

  
3
<Q4>
4
  {
5
    for $hr in //@xlink:href
6
    return <ns>{ $hr }</ns>
7
  }
8
</Q4>
src/use-cases/ns/q5.out
1
<Q5 xmlns:music="http://www.example.org/music/records">
2
<music:record>
3
    <music:artist>Wynton Marsalis</music:artist>
4
    <music:title>Think of One ...</music:title>
5
    <music:recorded>1983</music:recorded>
6
    <music:label>Columbia Records</music:label>
7

  
8
    <music:remark xml:lang="en"> Columbia Records 12" 33-1/3 rpm LP,
9
        #FC-38641, Stereo. The record is still clean and shiny and
10
        looks unplayed (looks like NM condition).  The cover has very
11
        light surface and edge wear.  
12
    </music:remark>
13
    <music:remark xml:lang="de"> Columbia Records 12" 33-1/3 rpm LP,
14
        #FC-38641, Stereo. Die Platte ist noch immer sauber und
15
        gl?nzend und sieht ungespielt aus (NM Zustand). Das Cover hat
16
        leichte Abnutzungen an Oberfl?che und Ecken.  
17
    </music:remark>
18
</music:record>
19
</Q5>
src/use-cases/ns/q5.xq
1
declare namespace music = "http://www.example.org/music/records";
2

  
3
<Q5>
4
  {
5
     //music:record[music:remark/@xml:lang = "de"]
6
  }
7
</Q5>
src/use-cases/ns/q6.out
1
<Q6 xmlns:ma="http://www.example.com/AuctionWatch">
2
  <ma:Close xmlns:dt="http://www.w3.org/2001/XMLSchema" dt:type="timeInstant">2000-03-23:07:41:34-05:00</ma:Close>
3
</Q6> 
src/use-cases/ns/q6.xq
1
declare namespace ma = "http://www.example.com/AuctionWatch";
2
declare namespace anyzone = "http://www.example.com/auctioneers#anyzone";
3

  
4
<Q6>
5
  {
6
    //ma:Auction[@anyzone:ID]/ma:Schedule/ma:Close
7
  }
8
</Q6>
src/use-cases/ns/q7.out
1
<Q7 xmlns:xlink="http://www.w3.org/1999/xlink"
2
    xmlns:ma="http://www.example.com/AuctionWatch" >
3
  <ma:AuctionHomepage xlink:type="simple"
4
                    xlink:href="http://auctions.yabadoo.com/auction/13143816" />
5
</Q7>
src/use-cases/ns/q7.xq
1
declare namespace ma = "http://www.example.com/AuctionWatch";
2

  
3
<Q7>
4
  {
5
    for $a in //ma:Auction
6
    let $seller_id := $a/ma:Trading_Partners/ma:Seller/*:ID,
7
        $buyer_id := $a/ma:Trading_Partners/ma:High_Bidder/*:ID
8
    where namespace-uri($seller_id) = namespace-uri($buyer_id)
9
    return
10
        $a/ma:AuctionHomepage
11
  }
12
</Q7>
src/use-cases/ns/q8.out
1
<Q8 xmlns:ma="http://www.example.com/AuctionWatch">
2
    <ma:High_Bidder xmlns:eachbay="http://www.example.com/auctioneers#eachbay" 
3
                    xmlns:xlink="http://www.w3.org/1999/xlink">
4
        <eachbay:ID>VintageRecordFreak</eachbay:ID>
5
        <eachbay:PositiveComments>232</eachbay:PositiveComments>
6
        <eachbay:NeutralComments>0</eachbay:NeutralComments>
7
        <eachbay:NegativeComments>0</eachbay:NegativeComments>
8
        <ma:MemberInfoPage xlink:type="simple" 
9
           xlink:href="http://auction.eachbay.com/showRating/user=VintageRecordFreak" 
10
           xlink:role="ma:MemberInfoPage"/>
11
    </ma:High_Bidder>
12
</Q8>
src/use-cases/ns/q8.xq
1
declare namespace ma = "http://www.example.com/AuctionWatch";
2

  
3
<Q8>
4
  {
5
    for $s in //ma:Trading_Partners/(ma:Seller | ma:High_Bidder)
6
    where $s/*:NegativeComments = 0
7
    return $s
8
  }
9
</Q8>
src/use-cases/parts/partlist.xml
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>
14

  
src/use-cases/parts/parts.dtd
1
    <!ELEMENT parttree (part*)>
2
    <!ELEMENT part (part*)>
3
    <!ATTLIST part
4
          partid  CDATA  #REQUIRED
5
          name    CDATA  #REQUIRED>
src/use-cases/parts/q1.out
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>
src/use-cases/parts/q1.xq
1
declare namespace f="my-functions.uri";
2
declare function f:one_level ($p as element()) as element()
3
{
4
    <part partid="{ $p/@partid }"
5
          name="{ $p/@name }" >
6
        {
7
            for $s in doc("partlist.xml")//part
8
            where $s/@partof = $p/@partid
9
            return f:one_level($s)
10
        }
11
    </part>
12
};
13

  
14
<parttree>
15
  {
16
    for $p in doc("partlist.xml")//part[empty(@partof)]
17
    return f:one_level($p)
18
  }
19
</parttree>
20

  
src/use-cases/r/addq1.xq
1
(: test sort with explicit collation :)
2
<result>
3
  {
4
    for $u in doc("users.xml")//user_tuple
5
    let $b := doc("bids.xml")//bid_tuple[userid = $u/userid]
6
    order by $u/name collation "http://saxon.sf.net/collation?lang=sv;strength=primary"
7
    return
8
        <user>
9
            { $u/userid }
10
            { $u/name }
11
            {
12
                if (empty($b))
13
                  then <status>inactive</status>
14
                  else <status>active</status>
15
            }
16
        </user>
17
  }
18
</result>
src/use-cases/r/bids.xml
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> 
7
</bid_tuple> 
8
<bid_tuple> 
9
<userid>U04</userid> 
10
<itemno>1001</itemno> 
11
<bid>40</bid> 
12
<bid_date>1999-01-08</bid_date >
13
</bid_tuple> 
14
<bid_tuple> 
15
<userid>U02</userid> 
16
<itemno>1001</itemno> 
17
<bid>45</bid> 
18
<bid_date>1999-01-11</bid_date>
19
</bid_tuple> 
20
<bid_tuple> 
21
<userid>U04</userid> 
22
<itemno>1001</itemno> 
23
<bid>50</bid> 
24
<bid_date>1999-01-13</bid_date >
25
</bid_tuple> 
26
<bid_tuple> 
27
<userid>U02</userid> 
28
<itemno>1001</itemno> 
29
<bid>55</bid> 
30
<bid_date>1999-01-15</bid_date> 
31
</bid_tuple> 
32
<bid_tuple> 
33
<userid>U01</userid> 
34
<itemno>1002</itemno> 
35
<bid>400</bid> 
36
<bid_date>1999-02-14</bid_date> 
37
</bid_tuple> 
38
<bid_tuple> 
39
<userid>U02</userid> 
40
<itemno>1002</itemno> 
41
<bid>600</bid> 
42
<bid_date>1999-02-16</bid_date> 
43
</bid_tuple> 
44
<bid_tuple> 
45
<userid>U03</userid> 
46
<itemno>1002</itemno> 
47
<bid>800</bid> 
48
<bid_date>1999-02-17</bid_date> 
49
</bid_tuple> 
50
<bid_tuple> 
51
<userid>U04</userid> 
52
<itemno>1002</itemno> 
53
<bid>1000</bid> 
54
<bid_date>1999-02-25</bid_date> 
55
</bid_tuple> 
56
<bid_tuple> 
57
<userid>U02</userid> 
58
<itemno>1002</itemno> 
59
<bid>1200</bid> 
60
<bid_date>1999-03-02</bid_date> 
61
</bid_tuple> 
62
<bid_tuple> 
63
<userid>U04</userid> 
64
<itemno>1003</itemno> 
65
<bid>15</bid> 
66
<bid_date>1999-01-22</bid_date> 
67
</bid_tuple> 
68
<bid_tuple> 
69
<userid>U05</userid> 
70
<itemno>1003</itemno> 
71
<bid>20</bid> 
72
<bid_date>1999-02-03</bid_date >
73
</bid_tuple> 
74
<bid_tuple> 
75
<userid>U01</userid> 
76
<itemno>1004</itemno> 
77
<bid>40</bid> 
78
<bid_date>1999-03-05</bid_date> 
79
</bid_tuple> 
80
<bid_tuple> 
81
<userid>U03</userid> 
82
<itemno>1007</itemno> 
83
<bid>175</bid> 
84
<bid_date>1999-01-25</bid_date> 
85
</bid_tuple> 
86
<bid_tuple> 
87
<userid>U05</userid> 
88
<itemno>1007</itemno> 
89
<bid>200</bid> 
90
<bid_date>1999-02-08</bid_date> 
91
</bid_tuple> 
92
<bid_tuple> 
93
<userid>U04</userid> 
94
<itemno>1007</itemno> 
95
<bid>225</bid> 
96
<bid_date>1999-02-12</bid_date> 
97
</bid_tuple> 
98
</bids>
99

  
100

  
src/use-cases/r/items.xml
1
<items>
2
<item_tuple><itemno>1001</itemno><description>Red Bicycle</description><offered_by>U01</offered_by><start_date>1999-01-05</start_date><end_date>1999-01-20</end_date><reserve_price>40</reserve_price></item_tuple>
3
<item_tuple><itemno>1002</itemno><description>Motorcycle</description><offered_by>U02</offered_by><start_date>1999-02-11</start_date><end_date>1999-03-15</end_date><reserve_price>500</reserve_price></item_tuple>
4
<item_tuple><itemno>1003</itemno><description>Old Bicycle</description><offered_by>U02</offered_by><start_date>1999-01-10</start_date><end_date>1999-02-20</end_date><reserve_price>25</reserve_price></item_tuple>
5
<item_tuple><itemno>1004</itemno><description>Tricycle</description><offered_by>U01</offered_by><start_date>1999-02-25</start_date><end_date>1999-03-08</end_date><reserve_price>15</reserve_price></item_tuple>
6
<item_tuple><itemno>1005</itemno><description>Tennis Racket</description><offered_by>U03</offered_by><start_date>1999-03-19</start_date><end_date>1999-04-30</end_date><reserve_price>20</reserve_price></item_tuple>
7
<item_tuple><itemno>1006</itemno><description>Helicopter</description><offered_by>U03</offered_by><start_date>1999-05-05</start_date><end_date>1999-05-25</end_date><reserve_price>50000</reserve_price></item_tuple>
8
<item_tuple><itemno>1007</itemno><description>Racing Bicycle</description><offered_by>U04</offered_by><start_date>1999-01-20</start_date><end_date>1999-02-20</end_date><reserve_price>200</reserve_price></item_tuple>
9
<item_tuple><itemno>1008</itemno><description>Broken Bicycle</description><offered_by>U01</offered_by><start_date>1999-02-05</start_date><end_date>1999-03-06</end_date><reserve_price>25</reserve_price></item_tuple>
10
</items>
src/use-cases/r/q1.out
1
<result>
2
    <item_tuple>
3
        <itemno>1003</itemno>
4
        <description>Old Bicycle</description>
5
    </item_tuple>
6
    <item_tuple>
7
        <itemno>1007</itemno>
8
        <description>Racing Bicycle</description>
9
    </item_tuple>
10
</result>
src/use-cases/r/q1.xq
1
<result>
2
  {
3
  let $current-date := xs:date('1999-01-31') return
4
    for $i in doc("items.xml")//item_tuple
5
    where $i/start_date <= $current-date
6
      and $i/end_date >= $current-date 
7
      and contains($i/description, "Bicycle")
8
    order by $i/itemno
9
    return
10
        <item_tuple>
11
            { $i/itemno }
12
            { $i/description }
13
        </item_tuple>
14
  }
15
</result>
src/use-cases/r/q10.out
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>
src/use-cases/r/q10.xq
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(for $z in doc("bids.xml")//bid_tuple[itemno=$highbid/itemno]/bid
7
                             return number($z))
8
    order by $highbid/itemno
9
    return
10
        <high_bid>
11
            { $highbid/itemno }
12
            { $highbid/bid }
13
            <bidder>{ $user/name/text() }</bidder>
14
        </high_bid>
15
  }
16
</result>
src/use-cases/r/q11.out
1
<result>
2
    <expensive_item>
3
        <itemno>1002</itemno>
4
        <description>Motorcycle</description>
5
        <high_bid>1200.0</high_bid>
6
    </expensive_item>
7
</result>
src/use-cases/r/q11.xq
1
let $highbid := max(for $z in doc("bids.xml")//bid_tuple/bid return number($z))
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>
src/use-cases/r/q12.out
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>
src/use-cases/r/q12.xq
1
declare namespace my="my.uri";
2

  
3
declare function my:bid_summary()
4
  as element()*
5
{
6
    for $i in distinct-values(doc("bids.xml")//itemno)
7
    let $b := doc("bids.xml")//bid_tuple[itemno = $i]
8
    return
9
        <bid_count>
10
            <itemno>{ $i }</itemno>
11
            <nbids>{ count($b) }</nbids>
12
        </bid_count>
13
};
14

  
15
<result>
16
 {
17
    let $bid_counts := my:bid_summary(),
18
        $maxbids := max(for $z in $bid_counts/nbids return number($z)),
19
        $maxitemnos := $bid_counts[nbids = $maxbids]
20
    for $item in doc("items.xml")//item_tuple,
21
        $bc in $bid_counts
22
    where $bc/nbids =  $maxbids and $item/itemno = $bc/itemno
23
    return
24
        <popular_item>
25
            { $item/itemno }
26
            { $item/description }
27
            <bid_count>{ $bc/nbids/text() }</bid_count>
28
        </popular_item>
29
 }
30
</result>
src/use-cases/r/q12temp.xq
1
declare namespace my="my.uri"
2
define function my:bid_summary()
3
  as element()*
4
{
5
for $i in distinct-values(doc("bids.xml")//itemno)
6
  let $b := doc("bids.xml")//bid_tuple[itemno = $i] 
7
  return <itemno>{ $i }</itemno>
8
}
9
my:bid_summary()  
10

  
11

  
12
        
src/use-cases/r/q13.out
1
<result>
2
    <bidder>
3
        <userid>U01</userid>
4
        <name>Tom Jones</name>
5
        <bidcount>2</bidcount>
6
        <avgbid>220.0</avgbid>
7
    </bidder>
8
    <bidder>
9
        <userid>U02</userid>
10
        <name>Mary Doe</name>
11
        <bidcount>5</bidcount>
12
        <avgbid>387.0</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.0</avgbid>
25
    </bidder>
26
    <bidder>
27
        <userid>U05</userid>
28
        <name>Jack Sprat</name>
29
        <bidcount>2</bidcount>
30
        <avgbid>110.0</avgbid>
31
    </bidder>
32
</result>
src/use-cases/r/q13.xq
1
<result>
2
 {
3
    for $uid in distinct-values(doc("bids.xml")//userid),
4
        $u in doc("users.xml")//user_tuple[userid = $uid]
5
    let $b := doc("bids.xml")//bid_tuple[userid = $uid]
6
    order by $u/userid
7
    return
8
        <bidder>
9
            { $u/userid }
10
            { $u/name }
11
            <bidcount>{ count($b) }</bidcount>
12
            <avgbid>{ avg($b/bid) }</avgbid>
13
        </bidder>
14
  }
15
</result>
src/use-cases/r/q14.out
1
<result>
2
    <popular_item>
3
        <itemno>1002</itemno>
4
        <avgbid>800.0</avgbid>
5
    </popular_item>
6
    <popular_item>
7
        <itemno>1007</itemno>
8
        <avgbid>200.0</avgbid>
9
    </popular_item>
10
    <popular_item>
11
        <itemno>1001</itemno>
12
        <avgbid>45.0</avgbid>
13
    </popular_item>
14
</result>
src/use-cases/r/q14.xq
1
<result>
2
 {
3
    for $i in distinct-values(doc("bids.xml")//itemno)
4
    let $b := doc("bids.xml")//bid_tuple[itemno = $i]
5
    let $avgbid := avg($b/bid)
6
    where count($b) >= 3
7
    order by $avgbid descending
8
    return
9
        <popular_item>
10
            <itemno>{ $i }</itemno>
11
            <avgbid>{ $avgbid }</avgbid>
12
        </popular_item>
13
  }
14
</result>
src/use-cases/r/q15.out
1
<result>
2
    <big_spender>Mary Doe</big_spender>
3
    <big_spender>Dee Linquent</big_spender>
4
    <big_spender>Roger Smith</big_spender>
5
</result>
src/use-cases/r/q15.xq
1
<result>
2
  {
3
    for $u in doc("users.xml")//user_tuple
4
    let $b := doc("bids.xml")//bid_tuple[userid=$u/userid and bid>=100]
5
    where count($b) > 1
6
    return
7
        <big_spender>{ $u/name/text() }</big_spender>
8
  }
9
</result>
src/use-cases/r/q16.out
1
<result>
2
    <user>
3
        <userid>U01</userid>
4
        <name>Tom Jones</name>
5
        <status>active</status>
6
    </user>
7
    <user>
8
        <userid>U02</userid>
9
        <name>Mary Doe</name>
10
        <status>active</status>
11
    </user>
12
    <user>
13
        <userid>U03</userid>
14
        <name>Dee Linquent</name>
15
        <status>active</status>
16
    </user>
17
    <user>
18
        <userid>U04</userid>
19
        <name>Roger Smith</name>
20
        <status>active</status>
21
    </user>
22
    <user>
23
        <userid>U05</userid>
24
        <name>Jack Sprat</name>
25
        <status>active</status>
26
    </user>
27
    <user>
28
        <userid>U06</userid>
29
        <name>Rip Van Winkle</name>
30
        <status>inactive</status>
31
    </user>
32
</result>
src/use-cases/r/q16.xq
1
<result>
2
  {
3
    for $u in doc("users.xml")//user_tuple
4
    let $b := doc("bids.xml")//bid_tuple[userid = $u/userid]
5
    order by $u/userid
6
    return
7
        <user>
8
            { $u/userid }
9
            { $u/name }
10
            {
11
                if (empty($b))
12
                  then <status>inactive</status>
13
                  else <status>active</status>
14
            }
15
        </user>
16
  }
17
</result>
src/use-cases/r/q17.out
1
<frequent_bidder />
src/use-cases/r/q17.xq
1
<frequent_bidder>
2
  {
3
    for $u in doc("users.xml")//user_tuple
4
    where 
5
      every $item in doc("items.xml")//item_tuple satisfies 
6
        some $b in doc("bids.xml")//bid_tuple satisfies 
7
          ($item/itemno = $b/itemno and $u/userid = $b/userid)
8
    return
9
        $u/name
10
  }
11
</frequent_bidder>
src/use-cases/r/q18.out
1
<result>
2
    <user>
3
        <name>Dee Linquent</name>
4
        <bid_on_item>Motorcycle</bid_on_item>
5
        <bid_on_item>Racing Bicycle</bid_on_item>
6
    </user>
7
    <user>
8
        <name>Jack Sprat</name>
9
        <bid_on_item>Old Bicycle</bid_on_item>
10
        <bid_on_item>Racing Bicycle</bid_on_item>
11
    </user>
12
    <user>
13
        <name>Mary Doe</name>
14
        <bid_on_item>Motorcycle</bid_on_item>
15
        <bid_on_item>Red Bicycle</bid_on_item>
16
    </user>
17
    <user>
18
        <name>Rip Van Winkle</name>
19
    </user>
20
    <user>
21
        <name>Roger Smith</name>
22
        <bid_on_item>Motorcycle</bid_on_item>
23
        <bid_on_item>Old Bicycle</bid_on_item>
24
        <bid_on_item>Racing Bicycle</bid_on_item>
25
        <bid_on_item>Red Bicycle</bid_on_item>
26
    </user>
27
    <user>
28
        <name>Tom Jones</name>
29
        <bid_on_item>Motorcycle</bid_on_item>
30
        <bid_on_item>Tricycle</bid_on_item>
31
    </user>
32
</result>
src/use-cases/r/q18.xq
1
<result>
2
  {
3
    for $u in doc("users.xml")//user_tuple
4
    order by $u/name
5
    return
6
        <user>
7
            { $u/name }
8
            {
9
                for $b in distinct-values(doc("bids.xml")//bid_tuple
10
                                             [userid = $u/userid]/itemno)
11
                for $i in doc("items.xml")//item_tuple[itemno = $b]
12
                let $descr := $i/description/text()
13
                order by $descr
14
                return
15
                    <bid_on_item>{ $descr }</bid_on_item>
16
            }
17
        </user>
18
  }
19
</result>
src/use-cases/r/q2.out
1
<result>
2
  <item_tuple>
3
    <itemno>1001</itemno>
4
    <description>Red Bicycle</description>
5
    <high_bid>55.0</high_bid>
6
  </item_tuple>
7
  <item_tuple>
8
    <itemno>1003</itemno>
9
    <description>Old Bicycle</description>
10
    <high_bid>20.0</high_bid>
11
  </item_tuple>
12
  <item_tuple>
13
    <itemno>1007</itemno>
14
    <description>Racing Bicycle</description>
15
    <high_bid>225.0</high_bid>
16
  </item_tuple>
17
  <item_tuple>
18
    <itemno>1008</itemno>
19
    <description>Broken Bicycle</description>
20
    <high_bid></high_bid>
21
  </item_tuple>
22
</result>
src/use-cases/r/q2.xq
1
<result>
2
  {
3
    for $i in doc("items.xml")//item_tuple
4
    let $b := doc("bids.xml")//bid_tuple[itemno = $i/itemno]
5
    where contains($i/description, "Bicycle")
6
    order by $i/itemno
7
    return
8
        <item_tuple>
9
            { $i/itemno }
10
            { $i/description }
11
            <high_bid>{ max($b/bid) }</high_bid>
12
        </item_tuple>
13
  }
14
</result>
src/use-cases/r/q3.out
1
<result>
2
    <warning>
3
        <name>Dee Linquent</name>
4
        <rating>D</rating>
5
        <description>Helicopter</description>
6
        <reserve_price>50000</reserve_price>
7
    </warning>
8
</result>
src/use-cases/r/q3.xq
1
<result>
2
  {
3
    for $u in doc("users.xml")//user_tuple
4
    for $i in doc("items.xml")//item_tuple
5
    where $u/rating > "C" 
6
       and $i/reserve_price > 1000 
7
       and $i/offered_by = $u/userid
8
    return
9
        <warning>
10
            { $u/name }
11
            { $u/rating }
12
            { $i/description }
13
            { $i/reserve_price }
14
        </warning>
15
  }
16
</result>
src/use-cases/r/q4.out
1
<result>
2
    <no_bid_item>
3
        <itemno>1005</itemno>
4
        <description>Tennis Racket</description>
5
    </no_bid_item>
6
    <no_bid_item>
7
        <itemno>1006</itemno>
8
        <description>Helicopter</description>
9
    </no_bid_item>
10
    <no_bid_item>
11
        <itemno>1008</itemno>
12
        <description>Broken Bicycle</description>
13
    </no_bid_item>
14
</result>
src/use-cases/r/q4.xq
1
<result>
2
  {
3
    for $i in doc("items.xml")//item_tuple
4
    where empty(doc("bids.xml")//bid_tuple[itemno = $i/itemno])
5
    return
6
        <no_bid_item>
7
            { $i/itemno }
8
            { $i/description }
9
        </no_bid_item>
10
  }
11
</result>
src/use-cases/r/q5.out
1
<result>
2
    <jones_bike>
3
        <itemno>1001</itemno>
4
        <description>Red Bicycle</description>
5
        <high_bid>
6
            <bid>55</bid>
7
        </high_bid>
8
        <high_bidder>
9
            <name>Mary Doe</name>
10
        </high_bidder>
11
    </jones_bike>
12
</result>
src/use-cases/r/q5.xq
1
<result>
2
  {
3
    for $seller in doc("users.xml")//user_tuple,
4
        $buyer in  doc("users.xml")//user_tuple,
5
        $item in  doc("items.xml")//item_tuple,
6
        $highbid in  doc("bids.xml")//bid_tuple
7
    where $seller/name = "Tom Jones"
8
      and $seller/userid  = $item/offered_by
9
      and contains($item/description , "Bicycle")
10
      and $item/itemno  = $highbid/itemno
11
      and $highbid/userid  = $buyer/userid
12
      and $highbid/bid = max(
13
                              doc("bids.xml")//bid_tuple
14
                                [itemno = $item/itemno]/bid
15
                         )
16
    order by ($item/itemno)
17
    return
18
        <jones_bike>
19
            { $item/itemno }
20
            { $item/description }
21
            <high_bid>{ $highbid/bid }</high_bid>
22
            <high_bidder>{ $buyer/name }</high_bidder>
23
        </jones_bike>
24
  }
25
</result>
src/use-cases/r/q5u.xq
1
<result>
2
  {
3
   unordered (
4
    for $seller in doc("users.xml")//user_tuple,
5
        $buyer in doc("users.xml")//user_tuple,
6
        $item in doc("items.xml")//item_tuple,
7
        $highbid in  doc("bids.xml")//bid_tuple
8
    where $seller/name = "Tom Jones"
9
      and $seller/userid  = $item/offered_by
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff