|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] xquery: iteration simulationMichalmas michalmas at gmail.comWed Mar 18 00:37:48 PST 2009
Hello guys, thanks a lot! Both solutions seems to be ok (i only had to fix some typos in Michael's solution, like missing '"' or too many ')' :P). The main purpose is, as Micheal guessed, histogram of some nodes. Best, M. On Mon, Mar 9, 2009 at 12:29 AM, Michael Kay <http://x-query.com/mailman/listinfo/talk> wrote: > Is "someStr" the same element name throughout? If so, it looks like this: > > declare function local:depth($e as element(*)) as xs:integer { > count($e/ancestor::*[node-name(.)=node-name($e)] > }; > > declare function local:histogram($root as element(mainNode), $name as > xs:QName) as element(count)* > for $d in distinct-values(mainNode//*[node-name()=$s]/local:depth(.)) > return <count element="{$name}" depth="{$d} > count="{count(mainNode//*[node-name()=$name][local:depth(.)=$d])) > } > > for $n in (xs:QName("", "someStr"), xs:QName("", "someOtherStr"), .....) > return local:histogram(mainNode, $n) > > Michael Kay > http://www.saxonica.com/ > > ------------------------------ > *From:* http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] *On > Behalf Of *Michalmas > *Sent:* 08 March 2009 20:29 > *To:* http://x-query.com/mailman/listinfo/talk > *Subject:* xquery: iteration simulation > > Hello guys, > > Can you help me with the following problem: > > I have some XML. > > Now, i need to query it. But what i need to do, is to make queries of the > form: > > count(mainNode//someStr) > count(mainNode//someStr/someStr) > (...) > > count(mainNode//someStr/someStr/someStr/someStr/someStr/someStr/someStr/someStr) > > The deep level of the last query may be even around 50 (so, 50 queries). > Such set of queries will be repeated for about 100 keywords (like someStr). > In total, that gives about 500 queries to create. > > Is is posible to write iteration in XQuery for that. Or pass it as a > function? > > Thanks, > M. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://x-query.com/pipermail/talk/attachments/20090318/9d0886ab/attachment.htm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






