<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.c9y6tc1
        {mso-style-name:c9y6tc1;
        color:blue;}
span.cn9ii1
        {mso-style-name:cn9ii1;
        color:#EA8F10;}
span.c18yc01
        {mso-style-name:c18yc01;
        color:#D00020;}
span.c5m9s01
        {mso-style-name:c5m9s01;
        color:#000090;}
span.c4zssg1
        {mso-style-name:c4zssg1;
        color:purple;}
span.cluy21
        {mso-style-name:cluy21;
        color:#EA8F0F;}
span.c49dik1
        {mso-style-name:c49dik1;
        color:#AC306D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>I am fairly sure I have answered my own question, but I still can&#8217;t believe it.<o:p></o:p></p><p class=MsoNormal>So maybe I&#8217;m missing something obvious.<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>Using XQuery<o:p></o:p></p><p class=MsoNormal>I need to create an XML file (in this case an XSLT file) with namespaces declared in the root node that are dynamically constructed.<o:p></o:p></p><p class=MsoNormal>I&#8217;d *<b>like</b>* to do something like this (which doesn&#8217;t work &#8230;)<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>&lt;transform&gt;<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp; { for $n in $my_namespaces <o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return attribute { concat(&#8220;xmlns:&#8221; , $n/@prefix ) } { $n/@uri } <o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></p><p class=MsoNormal>&#8230;<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>In this case the list of namespaces needed is *<b>not</b>* available as a static context in the XQuery.<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>The best I&#8217;ve done so far is to create&nbsp; bogus attributes in a computed namespace.<o:p></o:p></p><p class=MsoNormal>Actual code :<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><br><span style='color:blue'>document</span> {<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;<span style='color:#EA8F10'>xsl:stylesheet</span> <span style='color:#D00020'>version=</span><span style='color:#000090'>&quot;2.0&quot;</span> &gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='color:blue'>for</span> $ns <span style='color:blue'>in</span> $common:nsmap//ns<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='color:blue'>return</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='color:blue'>attribute</span> { fn:QName($ns/@uri, concat($ns/@prefix,<span style='color:purple'>&quot;:bogus&quot;</span>))} {}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></span></p><p class=MsoNormal>&#8230;.<o:p></o:p></p><p class=MsoNormal>}<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>This creates a bunch of &#8220;bogus&#8221; attributes and as a side effect also creates their namespace declarations.<o:p></o:p></p><p class=MsoNormal>Like this:<o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:blue'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:blue'>&lt;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#AC306D'>xsl:stylesheet </span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#D00020'>&nbsp;xmlns:xsl=</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#000090'>&quot;http://www.w3.org/1999/XSL/Transform&quot;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#D00020'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:ns1=</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#000090'>&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#D00020'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:ns2=</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#000090'>&quot;http://www.xmlsh.org/jxml&quot;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#D00020'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version=</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#000090'>&quot;2.0&quot;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#D00020'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ns1:bogus=</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#000090'>&quot;&quot;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#D00020'><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ns2:bogus=</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:#000090'>&quot;&quot;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif";color:blue'>&gt;</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>The typical case I&#8217;ve seen documented is to simply create the elements you need in the right namespace then namespace nodes get created properly.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>This works fine *<b>IF</b>* you are creating elements or attributes.&nbsp; But in my case I am creating the dreaded QNames in Conent.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>e.g&nbsp; XSLT Match expressions with prefixes &#8230; so there are no actual elements or attributers with the namespaces.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>My question &#8230; is there a &#8216;better&#8217; way of creating apparently unused namespace nodes using XQuery based on runtime data ?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:13.0pt;font-family:"Times New Roman","serif"'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:13.0pt;font-family:"Times New Roman","serif"'>Thanks for any suggestions.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:13.0pt;font-family:"Times New Roman","serif"'>Fortunately this &#8220;hack&#8221; actually works with XSLT as it ignores the bogus attributes &#8230; but if I were having to do this for another document type it may not.<o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>----------------------------------------</span><o:p></o:p></p><p class=MsoNormal>David A. Lee<o:p></o:p></p><p class=MsoNormal><a href="mailto:dlee@calldei.com"><span style='color:blue'>dlee@calldei.com</span></a><o:p></o:p></p><p class=MsoNormal><a href="http://www.xmlsh.org"><span style='color:blue'>http://www.xmlsh.org</span></a><o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>