W3C home > Mailing lists > Public > www-ql@w3.org > July to September 2005

Re: Renaming an element - getting a value without tags

From: David Sewell <dsewell@virginia.edu>
Date: Wed, 17 Aug 2005 20:11:15 -0400 (Eastern Daylight Time)
To: Jule Kleine <listmail@web.de>
Cc: www-ql@w3.org
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>.
Received on Thursday, 18 August 2005 00:11:22 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:17 UTC