Hi Leo,

> I thought the function local-name() produces an output  without namespace 
> binding? Can anyone explain?

You are completely right. The problem is that your original document
uses the default namespace "http://www.mygym.com";, and your query uses
"http://www.gym.com";. In other words, the error is raised because the
namespace binding of your target name conflicts with the existing
namespace binding.

Here is a recursive approach to change the default namespace of a document:
______________________________________

declare function local:update($root as node(), $ns as xs:string) {
  if($root instance of element()) then (
    element { QName($ns, local-name($root)) } {
      $root/@*,
      for $node in $root/node()
      return local:update($node, $ns)
    }
  ) else (
    $root
  )
};

let $ns := 'http://www.gym.com'
let $root := doc("FitnessCenter.xml")/*
let $updated := local:update($root, $ns)
return replace node $root with $updated
______________________________________

Hope this helps,
Christian



On Tue, Sep 16, 2014 at 12:10 PM, Leo Studer <leo.stu...@varioweb.ch> wrote:
> Hello
>
> I use the following query with Saxon-EE xQuery 9.5.1.5 in Oxygen.
>
> for $i in doc('FitnessCenter.xml')//*
>         return rename node $i as QName('http://www.gym.com', local-name($i))
>
>
> on the following file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <FitnessCenter xmlns="http://www.mygym.com";>
>         <Member Level="platinum">
>                 <Name>Jeff</Name>
>                 <FavoriteColor>lightgrey</FavoriteColor>
>         </Member>
>         <Member Level="gold">
>                 <Name>David</Name>
>                 <FavoriteColor>lightblue</FavoriteColor>
>         </Member>
> </FitnessCenter>
>
> and get the following error: new name conflicts with existing namespace 
> binding
>
>
> I thought the function local-name() produces an output  without namespace 
> binding? Can anyone explain?
>
> Thanks in advance
> Leo
>
>
> _______________________________________________
> talk@x-query.com
> http://x-query.com/mailman/listinfo/talk
_______________________________________________
talk@x-query.com
http://x-query.com/mailman/listinfo/talk

Reply via email to