Retrieve XML data using Xquery FLWOR

Last post 07-08-2008 3:53 AM by Samu Zhang - MSFT. 3 replies.

Sort Posts:

  • Retrieve XML data using Xquery FLWOR

    07-03-2008, 3:54 AM
    • Loading...
    • fredyw
    • Joined on 07-03-2008, 7:44 AM
    • Posts 16

     Hi,

    I have 3 XML data files, one is order, one is orderitems and last one is customer,

    e.g.

    order.xml

    orderitems.xml

    customer.xml

     

    I know that using xquery FLWOR function can query the data to join two or three files (like SQL query data by joining two or above files), how can I implement on ASP.NET using VB or C# !  or can I only use xpath to accomplish it. (I don't want to using any DBMS e.g. SQL2005, MySQL,etc)

    Please help! Thanks!

     

     

  • Re: Retrieve XML data using Xquery FLWOR

    07-03-2008, 7:23 AM

     

    Saxon 9.1 has an xquery API for free - it is very good.

    Look here: http://saxon.sourceforge.net/


     

    If I was helpful, please mark "answered" so I can get credit. Thanks!
  • Re: Retrieve XML data using Xquery FLWOR

    07-04-2008, 4:08 AM
    • Loading...
    • fredyw
    • Joined on 07-03-2008, 7:44 AM
    • Posts 16

     Thanks, but such 3rd party xquery tools for my project is not allowed.

  • Re: Retrieve XML data using Xquery FLWOR

    07-08-2008, 3:53 AM
    Answer

    Hi fredyw ,

    You can use xslt to do this.

    See my sample,

    xmlfile73.xml :

     

    <staffs>
    
      <staff order ="1">
    
        <name>wang </name>
    
        <age>27 </age>
    
    
      </staff>
    
      <staff order ="2">
    
        <name>Li </name>
    
        <age>24 </age>
    
    
      </staff>
    
      <staff order ="3">
    
        <name>Q1 </name>
    
        <age>29 </age>
    
    
      </staff>
    
    
    </staffs>

     xmlfile74.xml :

     <staffs>
      
         <staff order ="1">
        
             <name>wang </name>
        
             <Money>100 </Money>
        
        
      </staff>
      
         <staff order ="2">
        
             <name>Li </name>
        
             <Money>200 </Money>
        
        
      </staff>
      
         <staff order ="3">
        
             <name>Q1 </name>
        
             <Money>400 </Money>
        
        
      </staff>
      
      
    </staffs>

     xslt file:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:output  method="xml" omit-xml-declaration="yes"/>
    
      <xsl:variable name="file2" select="document('XMLFile74.xml')"/>
    
      <xsl:template match="/">
    
        <staffs>
    
          <xsl:for-each select="/staffs/staff">
    
            <xsl:variable name="CurrentOrder">
              <xsl:value-of select ="attribute::order" />
            </xsl:variable>
    
            <staff>
    
              <xsl:attribute name="order">
                <xsl:value-of select="@order" />
              </xsl:attribute>
    
              <xsl:copy-of select="name" />
    
              <xsl:copy-of select="age" />
    
              <xsl:copy-of select="$file2/staffs/staff[@order=$CurrentOrder]/Money" />
    
    
            </staff>
    
    
          </xsl:for-each>
    
    
        </staffs>
    
    
      </xsl:template>
    
    
    </xsl:stylesheet>

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter