Hi,

There are some design flaws in your code, from a brief look. I would expect 
non-element child nodes to get stripped from the result, I don't think you want 
that. Next to this, your addnamespace extracts the prefix from the node at 
hand, but none in your input has any. So I would expect none to get prefixed.

But to save you some time puzzling over this task, you could take a look at the 
following page and see if that code solves your problem:

http://www.xqueryfunctions.com/xq/functx_change-element-ns-deep.html

:-)

Kind regards,
Geert



Drs. G.P.H. Josten
Consultant




<http://www.daidalos.nl/>
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl<http://www.daidalos.nl/>
KvK 27164984


De informatie - verzonden in of met dit emailbericht - is afkomstig van 
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit 
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit 
bericht kunnen geen rechten worden ontleend.

________________________________
From: [email protected] 
[mailto:[email protected]] On Behalf Of test user
Sent: donderdag 9 april 2009 16:41
To: [email protected]
Subject: [MarkLogic Dev General] Problem regarding adding prefixes to the xml 
nodes

Hi,

I need to add prefixes to all element nodes(parent and child elements)

Input Xml:

     <Repeater>
        <ItemTemplate>
             <Button>
             </Button>
        </ItemTemplate>
     </Repeater>

Desired Output:

     <asp:Repeater>
        <asp:ItemTemplate>
             <asp:Button>
             </asp:Button>
        </asp:ItemTemplate>
     </asp:Repeater>

Please find the below function for the same.


declare namespace asp="http://asp<http://asp/>"
define function prefixadd($node)
{
   if($node instance of element()) then
         if (empty(getchildnodes($node))) then (
              addnamespace($node)
                )
         else
         (
           for $c at $j in getchildnodes($node)
            return
           (
                      prefixadd($c  )
        )
   else if($node instance of text()) then ()
   else ()
}
define function getchildnodes($node)
{
  let $childnodes := for $i in $node/child::node()
  return if($i instance of element()) then $i else ()
  return $childnodes
}
define function addnamespace($node)
{
let $node-name := fn:node-name($node)
let $prefix := fn:prefix-from-QName($node-name)
let $lname := fn:get-local-name-from-QName($node-name)
return (if ($prefix) then () else 
(xdmp:set($node,xdmp:unquote(replace(xdmp:quote($node),name($node),concat('asp:',name($node)))))),
  $node)
}

I'm able to prefix the namespace only at a single level. But i want it to be 
prefixed at all levels.
Kindly help with this
Thanks,
Prassu


_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to