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

Re: Controlling number of occurrences

Subject: Re: Controlling number of occurrences
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 13 Aug 2001 15:55:15 +0100
number of occurrence using xsl
Hi Jennifer,

> Is it possible (using xsl) to limit any repeat occurences of exact
> strings of text to one, so that I could use the following template
> to output a page that shows all *scripts and filenames* for a
> particular character. Right now, obviously, the character data is
> repeated. The XML I am pulling data from is a merged file of all of
> the XMLs for a particular project.

This is a grouping problem. You need to group the audio elements by
the character child element so that you can isolate the audio elements
with the first occurrence of each specific character element.

One way to do that is with the Muenchian method. Set up a key that
indexes the audio elements by the value of their character element
child:

<xsl:key name="audio-by-character" match="audio" use="character" />

Now you can get all the audio elements with a specific character with:

  key('audio-by-character', $character)

You can find those audio elements that are the first audio elements
with a particular value for the character child with:

  //audio[generate-id() =
          generate-id(key('audio-by-character', character)[1])]

or:

  //audio[count(.|key('audio-by-character', character)[1]) = 1]

So you can get the output that I gather you want with something like:

  <xsl:for-each select="//audio[count(.|key('audio-by-character',
                                            character)[1]) = 1]">
    <xsl:sort select="character" />
    <tr>
      <td align="center" valign="top" colspan="2">
        <xsl:apply-templates select="character" />
      </td>
    </tr>
    <xsl:for-each select="key('audio-by-character', character)">
      <tr>
        <td align="left" valign="top" width="150">
          <xsl:apply-templates select="@filename" />
        </td>
        <td align="left" valign="top" width="450">
          <xsl:apply-templates select="script" />
        </td>
      </tr>
    </xsl:for-each>
  </xsl:for-each>

Or, of course, you could use moded templates instead.
  
I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


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.