xsl-list
[Top] [All Lists]

Realising when you hit the last match?

2005-03-03 08:07:10
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[(_at_)class='2000'] | //pdxc2:heading[(_at_)class='2003'] | //pdxc2:heading[(_at_)class='2008'] | //pdxc2:heading[(_at_)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.



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>