[xquery-talk] reconstructing missing attributes

David Carlisle davidc at nag.co.uk
Wed Feb 8 01:49:14 PST 2006


If your processor supports preceding-sibling then it's easy:

<x>
{/x/*/element {name()} {(.|preceding-sibling::*)[@id][last()]/@id}}
</x>

$ saxon8q -s abc.xml abc.xq
<?xml version="1.0" encoding="UTF-8"?>
<x>
   <a id="1"/>
   <a id="1"/>
   <a id="1"/>
   <a id="2"/>
   <b id="2"/>
   <b id="2"/>
   <b id="2"/>
   <c id="2"/>
   <a id="3"/>
   <a id="3"/>
   <b id="3"/>
   <c id="3"/>
   <c id="3"/>
   <a id="4"/>
   <a id="4"/>
   <a id="4"/>
   <a id="5"/>
   <b id="5"/>
   <b id="5"/>
   <a id="6"/>
</x>

if not it's slightly more tiresome but you can always rewrite the axis
in terms of <<

fullaxis.xsl rewites the above to
<x>
{//x/*/ element {name()}{(. |
(let $here := . return
   reverse(../*[. << $here]))
/.)[@id][last()]/@id}}
</x>

for example (which gives the same result in saxon)

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the talk mailing list