[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

How to add an optional attiribute to a constructed XML tag with XQuery ?

Geert Josten Geert.Josten at daidalos.nl
Tue Feb 17 07:34:02 PST 2009


  How to add an optional attiribute to a
	constructed	XML tag with XQuery ?
Hi,

How about something like this:

let $x:= doc("source.xml")
for $comp in $x/Unit/Data/Organization
return
<Unit>
<Company>
    {$comp/@*}
    </Detail></Detail>
</Company>
</Unit>

You can also name the attributes explicitly, wrap them in an if and a for loop if you like. But make sure to insert attributes before anything else within the contents of the Company element.

I am not sure what $org was referring to, but if you simply want to copy the attributes of the Organization element to the Company element, then the above should work.

Kind regards,
Geert



Drs. G.P.H. Josten
Consultant




<http://www.daidalos.nl/>
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl<http://www.daidalos.nl/>
KvK 27164984


De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.

From: http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Diraviam H
Sent: dinsdag 17 februari 2009 7:15
To: http://x-query.com/mailman/listinfo/talk
Subject:  How to add an optional attiribute to a constructed XML tag with XQuery ?

I am creating an XML file say A, from another xml file B. The content of file B will be changing and some tags can have optional attributes. I want to include the attribute in the constructed XML file tag(s) through Xquery, only when it is available in source file B.
I am trying something like this, where the attribute "name" is optional in source.

let $x:= doc("source.xml")
for $comp in $x/Unit/Data/Organization
return
<Unit>
<Company type="{$comp/@type}" primary="{$org/@primary}" {if(fn:exists($x/Unit/Data/Organization/@name)) then name="{$org/@name}" else "" } >
</Detail></Detail>
</Company>
</Unit>
DISCLAIMER:
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090217/7be09981/attachment.htm


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.