RE: Requirement: Dynamically add namespaces to new created elements.

Hello David,

Copying the measure from source requires changing the function signature to
receive measures as parameters rather than plain QNames.

Your function successfully generates an element with the appropriate QName
and namespace declaration (if copy namespaces is set to preserve,inherit) as
the element name, not using the QName as element content.

The simplest example that does not work is this one:

declare namespace xbrli = "http://www.xbrl.org/instance";

declare function local:f($q as xs:QName) as element()
{
	element xbrli:measure { $q }
}

local:f(QName("http://example.org","x"))

The namespace http://example.org is not copied to the xbrli:mesure element
regardless of the value in the copy namespaces declaration.

The function above generates:
<xbrli:measure xmlns:xbrli="http://www.xbrl.org/instance">x</xbrli:measure>

And the expected result (from user's perspective is)
<xbrli:measure xmlns:xbrli="http://www.xbrl.org/instance"
xmlns="http://example.org">x</xbrli:measure>

So the QName (content of xbrli:measure) can be resolved to the right
namespace.

The only solution to deal with this situation is creating the namespace on
the fly in a construction that would have a syntax like this:

declare function local:f($q as xs:QName) as element()
{
	element xbrli:measure { (namespace {namespace-prefix-from-QName($q)}
{namespace-uri-from-QName($q)} , $q) }
}

So the namespace is created on the fly. But this is illegal XQuery.

Regards,
IHR

Ignacio Hernandez-Ros
XBRL International Inc. - Technology Development
ihr@xbrl.org
Cell: +34 609027754

> -----Original Message-----
> From: David Carlisle [mailto:davidc@nag.co.uk]
> Sent: Tuesday, February 21, 2006 1:10 PM
> To: ihr@xbrl.org
> Cc: public-qt-comments@w3.org
> Subject: Re: Requirement: Dynamically add namespaces to new created
> elements.
> 
> 
> 
>   Looking at the current XQuery spec 1.0 I realized that it is not
> possible to
>   dynamically create a namespace declaration to an element when you are
>   dynamically creating the element or when using a QName as element
> content.
> 
> If I understand your example can't you just copy the measure element
> from your input (the namespace declaration will be added by the
> serialiser). If you do need to generate an in-scope namespace from
> scratch from a namespace that is neither in the source file nor query,
> it's true that XQuery doesn't have an analogue of XSLT's xsl:namespace
> instruction but it is still possible. Consider for example the following
> function which generates an element with specified name and a namespace
> declaration with a specifed prefix and URI.
> 
> It's called with three string literals below and generates
> <foobar xmlns:x="http://example.org"/>
> but of course the three parameters could be any string-valued
> expressions.
> 
> David
> 
> 
> 
> 
> declare function local:f ($elem as xs:string,$prefix as xs:string,$ns as
> xs:string) as element() {
> element {QName($ns,concat($prefix,":wibble"))}{
> element {$elem}{}
> }/*};
> 
> 
> 
> local:f("foobar","x","http://example.org")
> 
> 
> 
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________

Received on Tuesday, 21 February 2006 14:12:58 UTC