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

Realising when you hit the last match?

Subject: Realising when you hit the last match?
From: "Aaron McGrath" <aaronmcgrath@xxxxxxxxxxx>
Date: Thu, 03 Mar 2005 15:07:10 +0000
aaron mcgrath
Hi all!

Hit a bit of a problem...
Just can't seem to figure out when I am processing the last match.

Okay, goes a bit like this:

XML sample (please forgive the syntax, hopefully it paints a clear enough picture):

<heading class='2001'>
   <heading class='2003'>
       <heading class='2000'>
       </heading>
   </heading class>
   <heading class='2000'>
       <heading class='2003'>
           <heading class='2000'>
           </heading>
       </heading>
   </heading>
</heading>

Now, what I want to do is to find all headings that either have a class of '2000' or have a class of '2003'.
Then I would like to process them all together and when I hit the last one do something special.
Exactly what I want to do is to output the class value when a '2000' or '2003' is matched. But I would like them seperated with a comma. This means that when I hit the last one I do not want to whack out a comma.
Okay... sounds simple right?
It did to me too...
Until I realized that there might not be any '2000' or there might not be any '2003'.
The problem is then even more prominent when you consider that I am actually dealing with about 10 different class values. I have just done two here to give an example.


I am doing something like this:

<xsl:apply-templates select="//pdxc2:heading[@class='2000'] | //pdxc2:heading[@class='2003'] | //pdxc2:heading[@class='2008'] | //pdxc2:heading[@class='2009']"/>

So I am only interested in '2000', '2003', '2008' and '2009'.
As I said there may be multiples or even none of each class, so I can't guarantee that the last match of a class '2009' will be the last one to deal with.


I then have a template match for each class which then deals with the output.
This is where I get stuck. I have no idea how to know when I have hit the last match which could be any of the classes above.


I am trying to get an output like this(according to the sample xml above):

2003,
2000,
2000,
2003,
2000

Notice no comma on the end. Don't know about all of you, but aren't commas in these situations always an a issue in any language!?

Ahhhhhh  Help!
Thanks for any advice!

Aaron McGrath.

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.