This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Controlling number of occurrences


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]