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

Re: My Difficult counting problem

Subject: Re: My Difficult counting problem
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 22 Aug 2002 16:22:49 -0600 (MDT)
Re:  My Difficult counting problem
Girard Tim-TGIRARD1 wrote:
> hello,
> I need some help doing the following, I can't seem to figure out how to do
> this in XSL
> I need to convert something like this
> <myElement>
>    <foo name="foobar1"/>
>    <foo name="foobar2"/>
>    <foo name="foobar1"/>
>    <foo name="foobar3"/>
>    <foo name="foobar1"/>
>    <foo name="foobar1"/>
>    <foo name="foobar3"/>
> </myElement>
> and the output after running it through the XSL would be
> numberOccurrences[] = {1, 1, 2, 1, 3, 4, 2};
> basically for each foo with a duplicate name you put the occurrence number
> of it in the array at the correct position.

  <xsl:template match="myElement">
    <xsl:text>numberOccurrences[] = {</xsl:text>
    <xsl:for-each select="foo">
      <xsl:value-of select="count(preceding-sibling::foo[@name=current()/@name])+1"/>
      <xsl:if test="position() != last()">, </xsl:if>

If efficiency is an issue, xsl:key may be of some utility; it would be easy to
set up a key that does the same work as the preceding-sibling business.

   - Mike
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.