Hi,<br><br>It still gives me the same error:<br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">XQuery Serialization Error!<br>A document node may not have an attribute node or a namespace node as a child<br>
</blockquote><br>@Ken:<br>Yes, i meant last possible node that has a value for given attribute.<br><br><div class="gmail_quote">On Sun, Mar 8, 2009 at 2:32 PM, G. Ken Holman <span dir="ltr">&lt;<a href="mailto:gkholman@cranesoftwrights.com">gkholman@cranesoftwrights.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">At 2009-03-08 13:43 +0100, Michalmas wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
What i need to get in xquery is the last possible child&#39;s attribute.<br>
</blockquote>
<br></div>
It looks to me like you need the last possible descendant&#39;s attribute, not child.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Let&#39;s say i have following XML:<br>
<br>
&lt;a&gt;<br>
  &lt;aa lc=1&gt;<br>
     &lt;aaa lc=00&gt;<br>
     &lt;/aaa&gt;<br>
  &lt;/aa&gt;<br>
  &lt;bb lc=0&gt;<br>
  &lt;/bb&gt;<br>
  &lt;zz lc=1&gt;<br>
     &lt;ccc lc=123&gt;<br>
     &lt;/ccc&gt;<br>
  &lt;/zz&gt;<br>
&lt;/a&gt;<br>
<br>
and i want to get the last child of &#39;a&#39; node. So, in this case, it would be node &#39;ccc&#39;. Then, i want to get lc attribute - in this example, 123.<br>
</blockquote>
<br></div>
Two ways you could express it, based on how easy you think each will be maintained by someone reading your code:<br>
<br>
To be explicit, you want the attribute of the last descendant of the element:<br>
<br>
  a/descendant::*[last()]/@lc<br>
<br>
To be concise, you want the last attribute descending from the element:<br>
<br>
  (a//@lc)[last()]<br>
<br>
The code below shows both of those working ... and I doubt there would be any difference in execution time ... choose whichever one &quot;reads&quot; better from a maintenance perspective.<br>
<br>
I believe maintenance of transforms is as important as performance ... let the processor worry about the optimization of the performance.<br>
<br>
BTW, I&#39;m assuming you know the attribute&#39;s name.  There is no such concept as &quot;last specified attribute&quot; for a given element, because attributes along the attribute axis are in an arbitrary order, they are not in specified order.  I find many students assume that just because they specified attributes in a particular order they are going to find them in that order when they walk the attribute axis.  XML says that attributes are unordered.  In the data model, they have an order, you just don&#39;t know what that order is.  So you can reliably walk over an attribute axis multiple times in one transformation and get the attributes in the same order each time during that transformation, but they won&#39;t necessarily be in that order the next time or with another processor.<br>

<br>
I hope this helps.<br>
<br>
. . . . . . . . . . Ken<br>
<br>
t:\ftemp&gt;type michalmas.xml<div class="im"><br>
&lt;a&gt;<br>
  &lt;aa lc=&quot;1&quot;&gt;<br>
     &lt;aaa lc=&quot;00&quot;&gt;<br>
     &lt;/aaa&gt;<br>
  &lt;/aa&gt;<br>
  &lt;bb lc=&quot;0&quot;&gt;<br>
  &lt;/bb&gt;<br>
  &lt;zz lc=&quot;1&quot;&gt;<br>
     &lt;ccc lc=&quot;123&quot;&gt;<br>
     &lt;/ccc&gt;<br>
  &lt;/zz&gt;<br>
&lt;/a&gt;<br>
<br></div>
t:\ftemp&gt;type michalmas.xq<br>
string( a/descendant::*[last()]/@lc ),<br>
string( (a//@lc)[last()] )<br>
t:\ftemp&gt;xquery michalmas.xml michalmas.xq<br>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;123 123<br>
t:\ftemp&gt;<br>
<br>
--<br>
XQuery/XSLT training in Prague, CZ 2009-03 <a href="http://www.xmlprague.cz" target="_blank">http://www.xmlprague.cz</a><br>
XQuery/XSLT/XSL-FO training in Los Angeles/Anaheim - 2009-06-01/10<br>
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video<br>
Video lesson:    <a href="http://www.youtube.com/watch?v=PrNjJCh7Ppg&amp;fmt=18" target="_blank">http://www.youtube.com/watch?v=PrNjJCh7Ppg&amp;fmt=18</a><br>
Video overview:  <a href="http://www.youtube.com/watch?v=VTiodiij6gE&amp;fmt=18" target="_blank">http://www.youtube.com/watch?v=VTiodiij6gE&amp;fmt=18</a><br>
G. Ken Holman                 mailto:<a href="mailto:gkholman@CraneSoftwrights.com" target="_blank">gkholman@CraneSoftwrights.com</a><br>
Crane Softwrights Ltd.          <a href="http://www.CraneSoftwrights.com/q/" target="_blank">http://www.CraneSoftwrights.com/q/</a><br>
Male Cancer Awareness Nov&#39;07  <a href="http://www.CraneSoftwrights.com/q/bc" target="_blank">http://www.CraneSoftwrights.com/q/bc</a><br>
Legal business disclaimers:  <a href="http://www.CraneSoftwrights.com/legal" target="_blank">http://www.CraneSoftwrights.com/legal</a><br>
<br>
_______________________________________________<br>
<a href="mailto:talk@x-query.com" target="_blank">talk@x-query.com</a><br>
<a href="http://x-query.com/mailman/listinfo/talk" target="_blank">http://x-query.com/mailman/listinfo/talk</a><br>
</blockquote></div><br>