Re: Renaming an element - getting a value without tags

On Thu, 18 Aug 2005, Jule Kleine wrote:

> I would like to use xquery to rename an element:
>
> <text>
>  <old>value</old>
> </text>
>
>
> should then be:
>
> <text>
>  <new>value</new>
> </text>
>
> -----
>
> My XQuery is:
>
> for $text in doc("sample.xml")/text
>
> let $value := $text/old
> let $outputValue := <new>{$value}</new>
>
> return
> (
> <text>
>   {$outputValue}
> </text>
> )
>
>
> What I get is:
>
> <text>
> 	<new>
> 		<old>value</old>
> 	</new>
> </text>

The problem is the declaration

   let $value := $text/old

This selects *nodes*, not their contents.  You want

   let $value := $text/old/text()

or, alternatively,

   let $value := data($text/old)

Now the $value variable will contain the text content of <old>.

Received on Thursday, 18 August 2005 00:11:22 UTC