- From: Peter Fankhauser <fankhaus@ipsi.fhg.de>
- Date: Mon, 21 Jan 2002 19:11:31 +0100
- To: <www-ql@w3.org>
The query: ELEMENT { if $language = "french" then "titre" else "title" } { "LoTr" } indeed has type ELEMENT * {xs:string} The element-name may be computed by an arbitrary query expression; thus the above type is the most specific we can get. In principle, we need to even check (dynamically) that the expression if $language = "french" then "titre" else "title" indeed returns an NMToken (or more generally a qualified name - QName). Thus the correct query is: ELEMENT { TREAT AS xsd:NMToken ( if $language = "french" then "titre" else "title" ) } { "LoTr" } This checks at runtime whether or not "titre" and "title" are valid NMTokens. E.g.: the following query: ELEMENT { TREAT AS xsd:NMToken ( if $language = "french" then ./titre else ./title ) } { "LoTr" } will most likely be a (runtime) type error, because ./titre (or titre for short) returns a titre-element (or empty list) rather than a valid NMToken. It is an open issue whether or not such runtime tests are inserted (and performed) automatically. To accomplish a more specific type, you need to formulate this query as follows: if $language = "french" then <titre> {"LoTr"} </titre> else <titel> {"LoTr"} </titel> which has the type: (ELEMENT titre {xs:string} | ELEMENT titel {xs:string}) You can try sth. similar out (e.g.) at http://xml.ipsi.fhg.de/xquerydemo as follows: (1) Load (e.g.) the query "extraction1" (2) Substitute the query there (let $bib := cast as Bib (document("bib1.xml")/bib) return $bib/book/autor) with: let $bib := cast as Bib (document("bib1.xml")/bib) for $b in $bib/book return if ($b/@year/text() <= 2000) then <bookLastCentury>{$b/title/text()}</bookLastCentury> else <bookThisCentury>{$b/title/text()}</bookThisCentury> This query returns: <bookLastCentury>Data on the Web</bookLastCentury> <bookThisCentury>XML Query</bookThisCentury> of type: (element bookLastCentury { xsd:string *} | element bookThisCentury { xsd:string *} ) * Hope this clarifies, Peter PS.: the current online IPSI-XQ Demonstrator does have a few bugs (which we are working on). The Galax team (see http://www-db.research.bell-labs.com/galax/) also has a complete implementation of the XQuery Type System - and fewer bugs *grrr* ;) > -----Original Message----- > From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf > Of Martin Tapp > Sent: Freitag, 18. Januar 2002 21:50 > To: 'www-ql@w3.org' > Subject: FW: static typing and computed elements > > > Hi, > > //element { if $language = "french" then "titre" else "title" } { > "LoTR" } // has type //element * { xs:string } > > I was woundering if the type was element titre|title {xs:string}. > Thanks! > > Martin Tapp > > -----Original Message----- > From: Jerome Simeon [mailto:simeon@research.bell-labs.com] > Sent: Thursday, January 17, 2002 10:18 AM > To: hme@informatik.uni-rostock.de > Cc: www-ql@w3.org > Subject: Re: static typing and computed elements > > > Holger, > > The XQuery static typing handles dynamic element names fine. The trick > is to realize that wildcard names are part of the type system and can > be used to type such an operation. > > For instance: > > element title { "Lord of the Rings" } > has type > element title { xs:string } > > and: > > element { if $language = "french" then "titre" else "title" } { "LoTR" > } has type element * { xs:string } > > where the * is a wildcard that stands for all possible QNames. > > So you can statically type this expression without problem, you just > get a less precise type. > > You can see more details about the typing for element constructors in > section 4.4 of the XQuery formal semantics (June working draft). > > - Jerome > >
Received on Monday, 21 January 2002 13:15:38 UTC