RE: transform an attribute to an element

That would be the way. Although I am not sure if one of the prototypes
supports data($x/@a) instead (I think there is an issue on this).

 

Best regards

Michael

 

-----Original Message-----
From: Chen Ya Bing [mailto:iscp0054@nus.edu.sg] 
Sent: Monday, February 18, 2002 19:48 PM
To: Michael Rys
Cc: www-ql@w3.org
Subject: Re: transform an attribute to an element

 

could you give me more detail of how to use the data() function? 

is it like that:

 

for $x in document("test.xml")/test

return

          <test>

              <a> {$x/@a/data <mailto:%7b$x/@a/data> ()} </a>

              {$x/b}

         </test>


I tried to execute it with quip or microsoft demo, but both failed.
maybe they do not support it now.

 

Best regards,

 

----- Original Message ----- 

From: Michael Rys <mailto:mrys@microsoft.com>  

To: Chen Ya Bing <mailto:iscp0054@nus.edu.sg>  ; Jim Davies
<mailto:jdavies@neocore.com>  

Cc: www-ql@w3.org 

Sent: Tuesday, February 19, 2002 10:31 AM

Subject: RE: transform an attribute to an element

 

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 Tuesday, 19 February 2002 14:36:06 UTC