Re: Renaming an element - getting a value without tags
David Sewell <[email protected]> Wed, 17 Aug 2005 20:11:15 -0400 (Eastern Daylight Time)
| Newsgroups | gmane.comp.web.query-languages |
|---|---|
| Message-ID | <Pine.WNT.4.62.0508172009110.2604@student> |
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>.