<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:m = 
"http://schemas.microsoft.com/office/2004/12/omml" xmlns:o = 
"urn:schemas-microsoft-com:office:office" xmlns:v = 
"urn:schemas-microsoft-com:vml" xmlns:w = 
"urn:schemas-microsoft-com:office:word"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6001.18203" name=GENERATOR>
<STYLE>@font-face {
        font-family: Calibri;
}
@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; }
P.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
LI.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
DIV.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-compose
}
.MsoChpDefault {
        mso-style-type: export-only
}
DIV.Section1 {
        page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]--></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>Or a more precise equivalent would be</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>&lt;Company&gt;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>&nbsp; {$comp/(@type, @primary, @name)}</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>&nbsp; &lt;Detail/&gt;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>&lt;/Company&gt;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>If you really need to create a new attribute conditionally, 
rather than copying an existing one, then you have to use a computed attribute 
constructor</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>if (condition) then</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>&nbsp;&nbsp;&nbsp; attribute {...} 
{...}</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>else ()</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>Michael Kay</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=407161509-17022009><FONT face=Arial 
color=#0000ff size=2>http://www.saxonica.com/</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma size=2><B>From:</B> talk-bounces@x-query.com 
  [mailto:talk-bounces@x-query.com] <B>On Behalf Of </B>Geert 
  Josten<BR><B>Sent:</B> 17 February 2009 06:34<BR><B>To:</B> Diraviam H; 
  talk@x-query.com<BR><B>Subject:</B> RE: [xquery-talk] How to add an optional 
  attiribute to aconstructed XML tag with XQuery ?<BR></FONT><BR></DIV>
  <DIV></DIV>
  <DIV>
  <DIV dir=ltr align=left><FONT size=2>
  <P class=MsoNormal><SPAN class=399303006-17022009><FONT 
  color=#0000ff>Hi,</FONT></SPAN></P>
  <P class=MsoNormal><SPAN class=399303006-17022009><FONT 
  color=#0000ff></FONT></SPAN>&nbsp;</P>
  <P class=MsoNormal><SPAN class=399303006-17022009><FONT color=#0000ff>How 
  about something like this:</FONT></SPAN></P>
  <P class=MsoNormal><SPAN class=399303006-17022009><FONT 
  color=#0000ff></FONT></SPAN>&nbsp;</P>
  <P class=MsoNormal><FONT color=#0000ff>let $x:= 
  doc("source.xml")<o:p></o:p></FONT></P>
  <P class=MsoNormal><FONT color=#0000ff>for $comp in 
  $x/Unit/Data/Organization<o:p></o:p></FONT></P>
  <P class=MsoNormal><FONT color=#0000ff>return<o:p></o:p></FONT></P>
  <P class=MsoNormal><FONT color=#0000ff>&lt;Unit&gt;<o:p></o:p></FONT></P>
  <P class=MsoNormal><FONT color=#0000ff>&lt;Company&gt;</FONT></P>
  <P class=MsoNormal><o:p><SPAN class=399303006-17022009><FONT 
  color=#0000ff>&nbsp;&nbsp;&nbsp; </FONT><FONT 
  color=#ff0000>{$comp/@*}</FONT></SPAN></o:p></P>
  <P class=MsoNormal><FONT color=#0000ff><SPAN 
  class=399303006-17022009>&nbsp;&nbsp;&nbsp; 
  </SPAN>&lt;/Detail&gt;&lt;/Detail&gt;<o:p></o:p></FONT></P>
  <P class=MsoNormal><FONT color=#0000ff>&lt;/Company&gt;<o:p></o:p></FONT></P>
  <P class=MsoNormal><FONT 
  color=#0000ff>&lt;/Unit&gt;<o:p></o:p></FONT></P></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial 
  color=#0000ff size=2></FONT>&nbsp;</DIV>
  <DIV><SPAN class=399303006-17022009><FONT face=Arial color=#0000ff>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&nbsp;Company element.</FONT></SPAN></DIV>
  <DIV><SPAN class=399303006-17022009><FONT face=Arial 
  color=#0000ff></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=399303006-17022009><FONT face=Arial color=#0000ff>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.</FONT></SPAN></DIV>
  <DIV><SPAN class=399303006-17022009><FONT face=Arial 
  color=#0000ff></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=399303006-17022009><FONT face=Arial color=#0000ff>Kind 
  regards,</FONT></SPAN></DIV>
  <DIV><SPAN class=399303006-17022009><FONT face=Arial 
  color=#0000ff>Geert</FONT></SPAN></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2></FONT><BR></DIV>
  <BLOCKQUOTE 
  style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
    <DIV class=OutlookMessageHeader lang=en-us dir=ltr 
  align=left></DIV></BLOCKQUOTE></DIV>
  <DIV>&nbsp;&nbsp; 
  <TABLE class=MsoTableGrid 
  style="BORDER-COLLAPSE: collapse; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt" 
  cellSpacing=0 cellPadding=0 border=0>
    <TBODY>
    <TR style="HEIGHT: 49.25pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes">
      <TD 
      style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 149.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; HEIGHT: 49.25pt" 
      vAlign=top width=199>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B 
        style="mso-bidi-font-weight: normal"><SPAN 
        style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Verdana; mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B 
        style="mso-bidi-font-weight: normal"><SPAN 
        style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Verdana; mso-ansi-language: EN-US"><FONT 
        size=1>Drs. G.P.H. Josten</FONT></SPAN></B></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
        style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-ansi-language: EN-US"><FONT 
        size=1><EM>Consultant</EM></FONT></SPAN></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt">&nbsp;</P></TD>
      <TD 
      style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 315pt; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; HEIGHT: 49.25pt" 
      vAlign=top width=420>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
        style="FONT-SIZE: 8pt; FONT-FAMILY: Bembo; mso-ansi-language: EN-US"></SPAN>&nbsp;</P></TD></TR>
    <TR style="HEIGHT: 98.75pt; mso-yfti-irow: 1">
      <TD 
      style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 149.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; HEIGHT: 98.75pt" 
      vAlign=top width=199><SPAN lang=NL 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"><A 
        href="http://www.daidalos.nl/"></A>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B 
        style="mso-bidi-font-weight: normal"><SPAN lang=EN-GB 
        style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Verdana; mso-ansi-language: EN-GB"><FONT 
        size=1>Daidalos BV</FONT></SPAN></B></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-GB 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-ansi-language: EN-GB"><EM><FONT 
        size=1>Source of Innovation</FONT></EM></SPAN></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-GB 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-ansi-language: EN-GB"><FONT 
        size=1>Hoekeindsehof 1-4</FONT></SPAN></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-GB 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-ansi-language: EN-GB"><FONT 
        size=1>2665<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>JZ<SPAN 
        style="mso-spacerun: yes">&nbsp; </SPAN>Bleiswijk</FONT></SPAN></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=1><SPAN 
        lang=EN-GB 
        style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Verdana; mso-ansi-language: EN-GB"><FONT 
        size=1>Tel.:</FONT></SPAN><SPAN lang=EN-GB 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-ansi-language: EN-GB"> 
        <FONT size=1>+31</FONT> <FONT size=1>(0) 10 850 
        1200</FONT></SPAN></FONT></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=1><SPAN 
        style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Verdana; mso-ansi-language: EN-US"><FONT 
        size=1>Fax:</FONT> </SPAN><SPAN 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-ansi-language: EN-US">+<FONT 
        size=1>31 (0) 10 850 119</FONT></SPAN></FONT><SPAN lang=NL 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"><FONT 
        size=1>9</FONT></SPAN></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=NL 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"><A 
        href="http://www.daidalos.nl/"><FONT 
        size=1>www.daidalos.nl</FONT></A></SPAN></P><SPAN lang=NL 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=NL 
        style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"><FONT size=1>KvK 
        27164984</FONT></SPAN></P></SPAN><SPAN lang=NL 
        style="FONT-SIZE: 8pt; FONT-FAMILY: Bembo"></SPAN></SPAN><SPAN lang=NL 
        style="FONT-SIZE: 8pt; FONT-FAMILY: Bembo"></SPAN></TD>
      <TD 
      style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 315pt; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; HEIGHT: 98.75pt" 
      vAlign=top width=420>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=1><B 
        style="mso-bidi-font-weight: normal"><SPAN lang=EN-GB 
        style="COLOR: blue; FONT-FAMILY: Verdana; mso-ansi-language: EN-GB; mso-bidi-font-family: Arial"></SPAN></B><SPAN 
        lang=NL 
    style="FONT-SIZE: 8pt; FONT-FAMILY: Bembo"></SPAN></FONT></P></TD></TR>
    <TR style="HEIGHT: 74pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes">
      <TD 
      style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; WIDTH: 6.45in; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; HEIGHT: 74pt" 
      vAlign=top width=619 colSpan=2>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=NL 
        style="FONT-SIZE: 8pt; COLOR: #999999; FONT-FAMILY: Verdana"><FONT 
        size=1>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.</FONT></SPAN></P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=NL 
        style="FONT-SIZE: 8pt; FONT-FAMILY: Bembo"></SPAN>&nbsp;</P>
        <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=NL 
        style="FONT-SIZE: 8pt; FONT-FAMILY: Bembo">
        <BLOCKQUOTE 
        style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
          <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT 
          face=Tahoma size=2><B>From:</B> talk-bounces@x-query.com 
          [mailto:talk-bounces@x-query.com] <B>On Behalf Of </B>Diraviam 
          H<BR><B>Sent:</B> dinsdag 17 februari 2009 7:15<BR><B>To:</B> 
          talk@x-query.com<BR><B>Subject:</B> [xquery-talk] How to add an 
          optional attiribute to a constructed XML tag with XQuery 
          ?<BR></FONT><BR></DIV>
          <DIV></DIV>
          <DIV class=Section1>
          <P class=MsoNormal>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.<o:p></o:p></P>
          <P class=MsoNormal>I am trying something like this, where the 
          attribute "name" is optional in source.<o:p></o:p></P>
          <P class=MsoNormal><o:p>&nbsp;</o:p></P>
          <P class=MsoNormal>let $x:= doc("source.xml")<o:p></o:p></P>
          <P class=MsoNormal>for $comp in 
          $x/Unit/Data/Organization<o:p></o:p></P>
          <P class=MsoNormal>return<o:p></o:p></P>
          <P class=MsoNormal>&lt;Unit&gt;<o:p></o:p></P>
          <P class=MsoNormal>&lt;Company type="{$comp/@type}" 
          primary="{$org/@primary}" 
          {if(fn:exists($x/Unit/Data/Organization/@name)) then 
          name="{$org/@name}" else "" } &gt;<o:p></o:p></P>
          <P class=MsoNormal>&lt;/Detail&gt;&lt;/Detail&gt;<o:p></o:p></P>
          <P class=MsoNormal>&lt;/Company&gt;<o:p></o:p></P>
          <P class=MsoNormal>&lt;/Unit&gt;<o:p></o:p></P></DIV>
          <TABLE>
            <TBODY>
            <TR>
              <TD bgColor=#ffffff><FONT 
                color=#000000>DISCLAIMER:<BR>-----------------------------------------------------------------------------------------------------------------------<BR><BR>The 
                contents of this e-mail and any attachment(s) are confidential 
                and intended for the named recipient(s) only.<BR>It shall not 
                attach any liability on the originator or HCL or its affiliates. 
                Any views or opinions presented in <BR>this email are solely 
                those of the author and may not necessarily reflect the opinions 
                of HCL or its affiliates.<BR>Any form of reproduction, 
                dissemination, copying, disclosure, modification, distribution 
                and / or publication of <BR>this message without the prior 
                written consent of the author of this e-mail is strictly 
                prohibited. If you have <BR>received this email in error please 
                delete it and notify the sender immediately. Before opening any 
                mail and <BR>attachments please check them for viruses and 
                defect.<BR><BR>-----------------------------------------------------------------------------------------------------------------------<BR></FONT></TD></TR></TBODY></TABLE></BLOCKQUOTE></SPAN>
        <P></P></TD></TR></TBODY></TABLE></DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>