generate xml file by using xquery

Posted on 2011-05-02
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
    LVL 60

    Accepted Solution

    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
    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

    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
    For development I used Oxygen (
    As the XQuery processor I used Saxon 9.2 Home Edition (

    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('')
    let $authors := doc('')

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now