Count in XQuery giving strange results

7331

New Member
I'm trying to count how many trips have been taken to California within two datesI have the current XQuery that is as follows:\[code\]for $x in doc("triptracker.xml")/data/cities/city, $y in doc("triptracker.xml")/data/trips/triplet $date as xs:date := xs:date($y/date)where $x/cityName = $y/cityName and $x/state = "CA" and $date gt xs:date("2003-01-01") and $date lt xs:date("2006-12-31")return <Result>Trips to California: {count($y)}</Result>\[/code\]Which gives me the result set\[code\]<Result>Trips to California: 1</Result><Result>Trips to California: 1</Result><Result>Trips to California: 1</Result><Result>Trips to California: 1</Result><Result>Trips to California: 1</Result>\[/code\]Instead of just giving me a count of 5Here is the type of XML data being give for trip and city\[code\]<trips> <trip> <ssn>123-20-4567</ssn> <cityName>Tucson</cityName> <date>2001-08-11</date> </trip></trips><cities> <city> <cityName>Houston</cityName> <state>TX</state> <location> <latitude>29.76045</latitude> <longitude>-95.369784</longitude> </location> </city></cities>\[/code\]Any help would be greatly appreciated
 
Back
Top