[xquery-talk] XHTML namespace and doc() function

Srinivas Pandrangi srinivas at ipedo.com
Wed Jul 7 15:21:00 PDT 2004


As Michael says the way fn:doc() function resolves URIs is not affected by the namespace declarations in the query.

I suspect the problem david is seeing is that the name tests in the path expression //body//p are testing names in the xhtml namespace, thereby returning empty sequences (I assume the source documents are not XHTML documents).

One way to override the default element namespace in the scope of an element constructor is through namespace declaration attributes in the constructor. In your example, I assume, you want "p" elements in the xhtml namespace to appear in the results. You should be able to do this,

..
..
	<xh:body xmlns:xh="http://www.w3.org/1999/xhtml" xmlns="">
	  { for $i in doc("DPM0029.xml")//body//p
	    return 
 	  	<xh:p>{$i/*}</xh:p>
	  } 
 	</xh:body>
..

i.e., You change the namespace bindings within the scope of the element constructor of interest to you. That will let you avoid having to qualify names through out the query.

--Srinivas

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com]On Behalf
> Of Michael Rys
> Sent: Wednesday, July 07, 2004 1:48 PM
> To: David Sewell; talk at xquery.com
> Subject: RE: [xquery-talk] XHTML namespace and doc() function
> 
> 
> The fn:doc() function does not (or at least should not :-)) use the
> default element namespace to resolve relative URIs. It uses the base
> URI.
> 
> So it looks like a bug in the XQuery engine that you are using.
> 
> Best regards
> Michael
> 
> > -----Original Message-----
> > From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On
> Behalf
> > Of David Sewell
> > Sent: Wednesday, July 07, 2004 1:20 PM
> > To: talk at xquery.com
> > Subject: [xquery-talk] XHTML namespace and doc() function
> > 
> > I've just been wrestling with a problem that it turns out was
> discussed
> > last year on this list, in a brainteaser posted by Jason Hunter:
> > 
> >   http://xquery.com/pipermail/talk/2003-May/000009.html
> > 
> > The basic issue is that we want to generate valid XHTML with XQuery
> code
> > that makes use of doc() to retrieve things. So we started out trying
> > something like this:
> > 
> > 	default element namespace = "http://www.w3.org/1999/xhtml"
> > 
> > 	<html>
> > 	 <head><title>Test</title></head>
> > 	 <body>
> > 	 { doc("DPM0029.xml")//body//p }
> > 	 </body>
> > 	</html>
> > 
> > and discovered the problem that the doc() function here returns null
> > because it is looking in the XHTML namespace instead of for a local
> URI,
> > as someone else pointed out in answer to the brainteaser.
> > 
> > Nobody suggested what the best workaround is, however. Of course we
> > could omit the XHTML namespace reference and output a bare <html>
> element,
> > but let's say we want to be W3C-correct and include it. Are 
> we always
> > going to have to "shield" doc() calls by putting them in variables
> > and/or functions external to the element constructors? Is there
> another
> > technique? (If not, do other navigation functions like id() have
> similar
> > issues?)
> > 
> > Thanks for helping a newbie,
> > 
> > David S.
> > 
> > --
> > David Sewell, Editorial and Technical Manager
> > Electronic Imprint, The University of Virginia Press
> > PO Box 400318, Charlottesville, VA 22904-4318 USA
> > Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
> > Email: dsewell at virginia.edu   Tel: +1 434 924 9973
> > Web: http://www.ei.virginia.edu/
> > _______________________________________________
> > talk at xquery.com
> > http://xquery.com/mailman/listinfo/talk
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
> 



More information about the talk mailing list