- From: Michael Kay <mhk@mhk.me.uk>
- Date: Wed, 8 Sep 2004 17:34:35 +0100
- To: "'Howard Katz'" <howardk@fatdog.com>, "'Per Bothner'" <per@bothner.com>
- Cc: <www-ql@w3.org>
We've generally been trying to move to a situation where the namespace prefixes declared in the prolog are used only at compile time (which brings them into line with variable names and function names). A recent decision, not yet reflected in the WDs, is that the QName() constructor will only work with a string literal, in other words you can't write QName($param) where $param happens to start with a namespace prefix that's used in the prolog. I would suggest that rather than using a namespace prefix to refer to the URI, it's better in this situation to use a variable. In other words, rather than writing declare namespace foo = "http://foo/"; write declare variable $foo = "http://foo/"; This gives you much more flexibility. Note also the availability of the resolve-uri() function. Michael Kay > -----Original Message----- > From: Howard Katz [mailto:howardk@fatdog.com] > Sent: 08 September 2004 17:16 > To: Michael Kay; 'Per Bothner' > Cc: www-ql@w3.org > Subject: RE: Generating RDF-style URIs from a namespace > > The use case, which is still somewhat vague, is motivated by > the need to be > able to work with either qnames or uris (more properly, urirefs) in an > RDF-processing application, and to be able to > programmatically map back and > forth between the two. > > As a bit of quick background, in a typical RDF scenario the > sequence of > urirefs : > > http://foo/bar > http://foo/baz > ... > > can be said to represent resources belonging to the vocabulary > "http://foo/", where the "bar" and "baz" suffixes indicate > specific terms > within that vocabulary. Using qnames as a syntactic > shorthand, this list can > be represented more compactly and in more human-friendly fashion as : > > foo:bar > foo:baz > ... > > where the common component "http://foo/" is mapped to the qname prefix > "foo". This mapping looks very much like an XQuery namespace > declaration, > although it's not exactly the same thing. Close enough for a > cigar however. > RDF commonly uses this adaptation of the XML qname and > namespace concepts to > map from uris to qnames and back again. > > My original question was motivated by a question from a > colleague with whom > I'm just starting to explore the use of XQuery for processing RDF. His > specific question was : > > "I know that you can declare a namespace in the prolog (and > in a number of > other more subtle ways), but just how can you *use* it? The > specs only seem > to demonstrate use in direct constructors and the like; can > you just use it > to build URIs inline? i.e. I want to generate the sequence ( > http://foo/bar, > http://foo/baz ). Will this do: > > declare namespace foo="http://foo/" > foo:bar, foo:baz > > If this question and my recasting of it were somewhat vague, > I apologize. > We're just starting to explore this area, and we don't yet > understand enough > to be able to ask more meaningful questions or pose a more clearly > delineated use case at this point. That will come in time. > > In the meantime, both Paul and Per's response's have been > helpful to me. > It's now clear that in order to be able to use an XQuery namespace > declaration, the prefix-to-namespace mapping needs to be > known statically at > query time. In some RDF scenarios -- when you're working with > "well-known" > prefixes such as "rdf" and "owl" for example -- that works > just fine. In > other scenarios, where the uris are not well known and you > would need to be > able to generate the namespace mappings from the uris > dynamically, that > clearly won't work and straight string manipulation will have > to be used > instead. > > If and when I have a clearer understanding of what the issues > are and what a > clear and realistic use case might be, I'll be happy to post > that to the > list. > > Howard > > > > -----Original Message----- > > From: www-ql-request@w3.org > [mailto:www-ql-request@w3.org]On Behalf Of > > Michael Kay > > Sent: Wednesday, September 08, 2004 1:00 AM > > To: 'Per Bothner'; 'Howard Katz' > > Cc: www-ql@w3.org > > Subject: RE: Generating RDF-style URIs from a namespace > > > > > > > > I avoided weighing into this because I really found the > question very > > unclear, but since namespaces and QNames are such a thorny area > > (one that is > > still being refined in the spec) the use case deserves examination. > > > > Could you explain exactly what your input is, what your > desired output is, > > and what information is known statically? Preferably in > language that > > doesn't rely on any knowledge of RDF. > > > > Michael Kay > > > > > > > > > Paul Cotton wrote: > > > > > > > This means that the NamespaceDecl cannot contain > function calls or > > > > string concatentation. > > > > > > But the question wasn't generating namespaces, but > generating URIs. > > > > > > It seems to me you should be able to use a cast to a QName: > > > > > > declare namespace foo="http://foo/"; > > > for $name in ("bar", "baz") > > > let $qname := QName(concat("foo:",$name) return > > > xs:anyURI( concat(namespace-uri-from-QName($name), > > > local-name-from-QName($name))) > > > > > > or > > > > > > declare namespace foo="http://foo/"; > > > let $foo := namespace-uri-from-QName(QName("foo:unused")) > > > for $name in ("bar", "baz") > > > xs:anyURI( concat($foo, $name)) > > > -- > > > --Per Bothner > > > per@bothner.com http://per.bothner.com/ > > > > > > > > > > > >
Received on Wednesday, 8 September 2004 16:35:15 UTC