generate xml file by using xquery

Posted on 2011-05-02
Medium Priority
Last Modified: 2012-06-27
Hi everyone,,
This question is totally related to the last question that i asked before and Mr.Gertone answered it correctly
it was about generating xml file by using xslt
but in this case using xquery language
basically it's about generating new xml file (same as output.xml) by using xquery language
all the files are the same as it was in the last question.
please have a look to the four uploaded files.
could someone please "preferring Gertone :=)" write queries to
generate the xml file output.xml
just in case i'm using the open source software Kawa system to execute the xq file
thank you

 output.xml output-dtd.xml authors.xml artworks.xml
Question by:Hatim1985
  • 3
LVL 60

Accepted Solution

Geert Bormans earned 2000 total points
ID: 35503489
Here is an XQuery that does what you need using the processors I tested it with.
I did not test with Kawa for two reasons
- I don't have it on any of my machines
- I will not install or use it even for testing since it is incomplete (so useless in my mind)

I hope it works for you, if not, either find a different XQuery processor or remove the restrictions from the code

I will not work on any restrictions myself since I fear this is homework
(a task that needs to be done in XSLT first and then in XQuery and you don't seem to have a clue about any of the technologies smells like homework for me...
so the effort is yours from this point on)
let $artworks := doc('artworks.xml')
let $authors := doc('authors.xml')
    for $at in $authors//author
        let $at-name := $at/name/text()
        let $aw := $artworks//artwork[author/text() = $at-name]
                for $a in $at/*
                    return $a
                for $aw-form in distinct-values($aw/form/text())
                    <artworks form="{$aw-form}">
                        for $aws in $aw[form/text() = $aw-form]
                        order by $aws/date
                            <artwork date="{$aws/date}">
                                for $a in $aws/(title,technique,location)
                                    return $a

Open in new window

LVL 60

Expert Comment

by:Geert Bormans
ID: 35503514
Note that it is bad practice to ask for a particulare expert here.
Many can do what I just did and you just exclude them early on.
That is not smart because it lowers your chances of getting the answer you need

Author Comment

ID: 35510264
Hi Gertone,
i guess you exaggerated the situation over here ,, i think you still have the homework's smelling from the previous question
which i did answer it before. i'm sure that anyone in ee "not only you" will look at my questions as it's homework, but totally not !! :/
it might because im trying to simplify my requests and doing justifying..
anyway im not going through your consideration cos it's not part what im looking for here,
one more question to you,, could you please inform me what is the name of the software that you used
lastly your answer was very good !!
thank you
LVL 60

Expert Comment

by:Geert Bormans
ID: 35510329
For development I used Oxygen (www.oxygenxml.com)
As the XQuery processor I used Saxon 9.2 Home Edition (www.saxonica.com)

For verification I used the Zorba XQuery Sandbox
For that (avoiding to put the XML on the zorba website) I have put the source files on a website so they were accessible through http
let $artworks := doc('http://xxx.yyy.be/ee/artworks.xml')
let $authors := doc('http://xxx.yyy..be/ee/authors.xml')

And I have put the two XML files in a database and used the XQuery of the database to retrieve the results,
works equally well

So I tested: inside an IDE, through a sandbox on a file type processor and through a database interface... enough to say it works :-)

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Integration Management Part 2
Loops Section Overview
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question