[xquery-talk] Constructing namespace nodes

David Lee dlee at calldei.com
Sun Feb 6 12:59:17 PST 2011

I am fairly sure I have answered my own question, but I still can't believe

So maybe I'm missing something obvious.


Using XQuery

I need to create an XML file (in this case an XSLT file) with namespaces
declared in the root node that are dynamically constructed.

I'd *like* to do something like this (which doesn't work .)



   { for $n in $my_namespaces 

                return attribute { concat("xmlns:" , $n/@prefix ) } {
$n/@uri } 




In this case the list of namespaces needed is *not* available as a static
context in the XQuery.


The best I've done so far is to create  bogus attributes in a computed

Actual code :


document {
    <xsl:stylesheet version="2.0" >
        for $ns in $common:nsmap//ns
            attribute { fn:QName($ns/@uri, concat($ns/@prefix,":bogus"))} {}





This creates a bunch of "bogus" attributes and as a side effect also creates
their namespace declarations.

Like this:


<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"



The typical case I've seen documented is to simply create the elements you
need in the right namespace then namespace nodes get created properly.

This works fine *IF* you are creating elements or attributes.  But in my
case I am creating the dreaded QNames in Conent.

e.g  XSLT Match expressions with prefixes . so there are no actual elements
or attributers with the namespaces.


My question . is there a 'better' way of creating apparently unused
namespace nodes using XQuery based on runtime data ?


Thanks for any suggestions.

Fortunately this "hack" actually works with XSLT as it ignores the bogus
attributes . but if I were having to do this for another document type it
may not.










David A. Lee

 <mailto:dlee at calldei.com> dlee at calldei.com

 <http://www.xmlsh.org> http://www.xmlsh.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20110206/a5f53368/attachment.htm

More information about the talk mailing list