a question about return values and data query

Wednesday, 20 July 2011 · 2 messages
LW
Lusha Wang20 Jul 2011 02:00 #
Hi Everyone
    I have to questions:
    1) Is it possible to return sth formatted string like this:
        return  <Document>{$Document/HasDomain/@id /data()+"%%"+$Document/Time/text()}</Document>
        So far it shows errors.....I dont know if there are alternatives.
    2) I have data like this
          <Documents>
         <Document id="doc1">
             <Date>yyyy-mm-dd</Date>
             <HasIP ip="ip1">
             <HasDomain domain="domain1">
             <HasDomain domain="domain2">
          </Document>
         <Document id="doc1">
              <Date>yyyy-mm-dd</Date>
             <HasIP ip="ip2">
             <HasDomain domain="domain1">
             <HasDomain domain="domain3">
          </Document>
     </Documents>
     <IPs>
           <IP id="ip1">
             <data>111.111.111.111</data>
          </IP>
          <IP id="ip2">
             <data>111.111.111.112</data>
          </IP>
     </IPs>
     <Domains>
          <Domain id="domain1">
             <data>abc.com</data>
          </Domain>
          <Domain id="domain2">
             <data>edf.com</data>
          </Domain>
          <Domain id="domain3">
             <data>abc.com</data>
          </Domain>
      <Domains>
       I m trying to get all domains from documents that are within the following time period.
       for $Document in doc('test')//Document
       let $datestr := $Document/Date/text()
       let $date := xs:date($datestr)
       where $date<=xs:date("2010-05-02") and $date>xs:date("2010-05-01") and $Document/HasDomain
       return  <Document>{$Document/HasDomain, $Document/Time/text()}</Document>
However, only the domain ids are returned, I cant make the database return domain data rather than id. Can anyone offer me some suggestions? Thanks a lot. Sincerely Lusha
RS
Rositsa Shadura20 Jul 2011 13:22 #
Hi Lusha, I don't know if I understand your question correctly but I have come up with the following solution:
for $Document in doc('docs.xml')//Document[xs:date(./Date/text()) <=
xs:date("2010-05-02")]
   return <Document>{
     for $d in $Document/HasDomain/@domain/data()
       return <Domain>{attribute{"id"}{$d},
                       attribute{"data"}{doc('domains.xml')//Domain[@id/data()=$d]/data/text()}}
              </Domain>}
          </Document>
As a result I have:
<Document>
   <Domain id="domain1" data="abc.com"/>
   <Domain id="domain2" data="edf.com"/>
</Document>
<Document>
   <Domain id="domain1" data="abc.com"/>
   <Domain id="domain3" data="abc.com"/>
</Document>
docs.xml is the document with root "Documents" and domains.xml is the document with root "Domains". By the way, the docs.xml is not well-formed as the elements <HasDomain/> have no closing tags. Greetings, Rositsa
Quoted text · Lusha Wang · 59 lines
On Wed, 20 Jul 2011 02:00:09 +0200, Lusha Wang <lwang40 at syr.edu> wrote: > Hi Everyone > I have to questions: > 1) Is it possible to return sth formatted string like this: > return <Document>{$Document/HasDomain/@id > /data()+"%%"+$Document/Time/text()}</Document> > So far it shows errors.....I dont know if there are alternatives. > 2) I have data like this > <Documents> > <Document id="doc1"> > <Date>yyyy-mm-dd</Date> > <HasIP ip="ip1"> > <HasDomain domain="domain1"> > <HasDomain domain="domain2"> > </Document> > <Document id="doc1"> > <Date>yyyy-mm-dd</Date> > <HasIP ip="ip2"> > <HasDomain domain="domain1"> > <HasDomain domain="domain3"> > </Document> > </Documents> > <IPs> > <IP id="ip1"> > <data>111.111.111.111</data> > </IP> > <IP id="ip2"> > <data>111.111.111.112</data> > </IP> > </IPs> > <Domains> > <Domain id="domain1"> > <data>abc.com</data> > </Domain> > <Domain id="domain2"> > <data>edf.com</data> > </Domain> > <Domain id="domain3"> > <data>abc.com</data> > </Domain> > <Domains> > I m trying to get all domains from documents that are within the > following time period. > for $Document in doc('test')//Document > let $datestr := $Document/Date/text() > let $date := xs:date($datestr) > where $date<=xs:date("2010-05-02") and > $date>xs:date("2010-05-01") and $Document/HasDomain > return <Document>{$Document/HasDomain, > $Document/Time/text()}</Document> > > However, only the domain ids are returned, I cant make the > database return domain data rather than id. Can anyone offer me some > suggestions? Thanks a lot. > > > Sincerely > Lusha >
-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

⚡Generated with XQuery