|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] last possible child's attributeMichalmas michalmas at gmail.comSun Mar 8 14:45:34 PST 2009
Hi, It still gives me the same error: XQuery Serialization Error! > A document node may not have an attribute node or a namespace node as a > child > @Ken: Yes, i meant last possible node that has a value for given attribute. On Sun, Mar 8, 2009 at 2:32 PM, G. Ken Holman <http://x-query.com/mailman/listinfo/talk > wrote: > At 2009-03-08 13:43 +0100, Michalmas wrote: > >> What i need to get in xquery is the last possible child's attribute. >> > > It looks to me like you need the last possible descendant's attribute, not > child. > > Let's say i have following XML: >> >> <a> >> <aa lc=1> >> <aaa lc=00> >> </aaa> >> </aa> >> <bb lc=0> >> </bb> >> <zz lc=1> >> <ccc lc=123> >> </ccc> >> </zz> >> </a> >> >> and i want to get the last child of 'a' node. So, in this case, it would >> be node 'ccc'. Then, i want to get lc attribute - in this example, 123. >> > > Two ways you could express it, based on how easy you think each will be > maintained by someone reading your code: > > To be explicit, you want the attribute of the last descendant of the > element: > > a/descendant::*[last()]/@lc > > To be concise, you want the last attribute descending from the element: > > (a//@lc)[last()] > > The code below shows both of those working ... and I doubt there would be > any difference in execution time ... choose whichever one "reads" better > from a maintenance perspective. > > I believe maintenance of transforms is as important as performance ... let > the processor worry about the optimization of the performance. > > BTW, I'm assuming you know the attribute's name. There is no such concept > as "last specified attribute" 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'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't necessarily be in that order the next > time or with another processor. > > I hope this helps. > > . . . . . . . . . . Ken > > t:\ftemp>type michalmas.xml > <a> > <aa lc="1"> > <aaa lc="00"> > </aaa> > </aa> > <bb lc="0"> > </bb> > <zz lc="1"> > <ccc lc="123"> > </ccc> > </zz> > </a> > > t:\ftemp>type michalmas.xq > string( a/descendant::*[last()]/@lc ), > string( (a//@lc)[last()] ) > t:\ftemp>xquery michalmas.xml michalmas.xq > <?xml version="1.0" encoding="UTF-8"?>123 123 > t:\ftemp> > > -- > XQuery/XSLT training in Prague, CZ 2009-03 http://www.xmlprague.cz > XQuery/XSLT/XSL-FO training in Los Angeles/Anaheim - 2009-06-01/10 > Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video > Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 > Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 > G. Ken Holman mailto:http://x-query.com/mailman/listinfo/talk > Crane Softwrights Ltd. http://www.CraneSoftwrights.com/q/ > Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/q/bc > Legal business disclaimers: http://www.CraneSoftwrights.com/legal > > _______________________________________________ > http://x-query.com/mailman/listinfo/talk > http://x-query.com/mailman/listinfo/talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://x-query.com/pipermail/talk/attachments/20090308/186b77e9/attachment-0001.htm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






