- From: Michael Rys <mrys@microsoft.com>
- Date: Mon, 18 Feb 2002 18:31:28 -0800
- To: "Chen Ya Bing" <iscp0054@nus.edu.sg>, "Jim Davies" <jdavies@neocore.com>
- Cc: <www-ql@w3.org>
- Message-ID: <5C39F806F9939046B4B1AFE652500A3AB3A2D0@RED-MSG-10.redmond.corp.microsoft.com>
Text() is an XPath node test and thus cannot work on attributes (thanks
to XPath 1.0). Use data() instead.
Best regards
Michael
-----Original Message-----
From: Chen Ya Bing [mailto:iscp0054@nus.edu.sg]
Sent: Monday, February 18, 2002 18:29 PM
To: Jim Davies
Cc: www-ql@w3.org
Subject: Re: transform an attribute to an element
but it failed when using Quip from SoftwareAG. I think the function
text() can only apply to elements, not to attributes.
----- Original Message -----
From: Jim Davies <mailto:jdavies@neocore.com>
To: Chen Ya Bing <mailto:iscp0054@nus.edu.sg>
Sent: Tuesday, February 19, 2002 1:06 AM
Subject: RE: transform an attribute to an element
Hello,
You can do this fairly simply with a for loop and element constructors,
like this:
for $x in /test
return
<test>
<a>{$x/@a/text()}</a>
{$x/b}
</test>
where the text() is necessary to make sure that the value of @a gets
returned
rather than having it remain an attribute. Basically this loop just
takes
the original document apart and then re-assemble it without the
attribute but with
the new child element.
Hope that helps (I'm still learning this stuff also... :-)
Jim Davies
Senior Engineer
Neocore Inc.
jdavies@neocore.com
"There is a difference between knowing the path and walking the path."
-- Morpheus, "The Matrix"
-----Original Message-----
From: Chen Ya Bing [mailto:iscp0054@nus.edu.sg]
Sent: Monday, February 18, 2002 2:04 AM
To: www-ql@w3.org
Subject: transform an attribute to an element
Hi,
who can tell me if I can use XQuery to transform an attribute to an
element?
for example, the document is
<test a="123">
<b>321</b>
</test>
I'd like to transform the attribute "a" to an element of test.
<test>
<a>123</a>
<b>321</b>
</test>
thank you!
Received on Monday, 18 February 2002 21:32:38 UTC