[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: For-each loop or recursion

Subject: Re: For-each loop or recursion
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 16 May 2005 10:04:26 +0100
foreach last
> To be very honest, I am not totally sure myself about myarray1[i].

My pointwas that you said
> > I have the following data (leaves in parallel branches):
> > mystruct/myarray1[i]/myvar/var2 and

But that isn't your input data it's just some bit of XPath which is
syntactically correct but we can't give you any help as to whether it is
doing the right thing as you have  given no indication what your input
document looks like, what your required output looks like or what
transformation you are trying to achieve.

> I need to compare current and next values of the node var2 [and var3]
> and find the first occurrence when var2[position()] = var2[next, i.e.
> position()+1]
> Are you saying that is impossible to do in XSLT ?

It's almost certainly possible to do what you want but your decription
is pretty hard to follow. You need to describe the transformation that
you want to do not just use bits of XPath and hope that we understand
what you want.  Xpath's position() function for example does not relate
to the position of a node within a tree (a node can have any number of
values returned buy position(), depending on how the node is
selected). I'm _guessing_ that what you want to know is the sibling order
of the node in the input tree in which case you might want
following-sibling::*[1] but that is just a guess.

  I want from inside for-each loop mystruct/myarray1[i]/myvar
  [or does it require recursion?]
  compare the values is the parallel branch, 
  of parallel "current" node ../../myarray2[i]/myvar/var3 and its "next node".  
  Again, where:
  mystruct/myarray1[i]/myvar/var2 and
  mystruct/myarray2[i]/myvar/var3


Again you are just typing in syntactically correct XPath and asking "can
I do that" since the Xpath you typed above is syntactically correct then
clearly you can do that, but I have no idea if that will do what you
want, as you've not said what you are trying to do. For example do your
elements with name myarray1 have child elements with name i ? If they do
not, then the above XPath's will select nothing.

> Is there an easy way to find out the max value of the node (child elements)
> without sorting it ?
> The sequence of nodes I am dealing with is supposed to be in increasing order,

If you know it's already sorted, just take the last
select="*[last()]"
or in your case take the last of each then you only have two itemsto
compare which you can do with &gt; to work out the overall maximum.


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
________________________________________________________________________

Current Thread

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-2013 All Rights Reserved.