xsl-list
[Top] [All Lists]

compare out of context?

2004-11-02 09:46:37
Hi everyone.

New to the list and already I'm coming with my troubles. :-)

I've got a problem accessing some data higher up the node-tree in XSL.
Hopefully you can help me.

From the XML source data below you'll notice that I'm building a music
listing. The data enclosed contains 2 albums, 5 tracks and 4 different
artists and the structure is pretty flat.

I do a double grouping, once per artist, then per album. Underneath all this
I list the various tracks. The particularity is that I list not only the
tracks the artist has participated on but the whole list of tracks for a
particular record. All this I've achieved already and looks like this:

- artist1
  - album1
    - track1
    - track2
  - album2
    - track1
    - track2
- artist2
  - album1
    - track1


Looking at the data supplied this gives us:

- Artemis
  - Earth Volume 2
    - Fictions
    - Silver Dawn
    - Artifical Life
- Odyssey
  - Earth Volume 2
    - Fictions
    - Silver Dawn
    - Artifical Life
- Pearl Jam
  - Ten
    - Why Go
    - Black
- Rollercone
  - Earth Volume 2
    - Fictions
    - Silver Dawn
    - Artifical Life

What I'm breaking my teeth on is the following: I would like to compare the
name of the artist at the track level to the name of the artist I'm
currently working with at the top level.

Given the following data:
- 1
  - 1.1
    - 1.1.1
    - 1.1.2
    - 1.1.3
I would like to compare the artist name of "1.1.3" with the artist name of
"1" and if they are the same then do some text formatting. The problem I
have is that I have not found a way to get the name of the artist at "1". I
had hoped it would be as simple as doing a simple test like the one below,
but alas, that was a little too optimistic.

  <xsl:if test="../../artist/displayname != artist/displayname">

Below is my XSL code as well as some XML source. I'd be grateful if you
could have a look at it.

- Thomas


-------[BEGIN SOURCE XSL]--------
<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html"
     doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>

<xsl:key name="artists"
         match="mp3"
         use="artist/displayname" />
<xsl:key name="albums"
         match="mp3"
         use="album/displayname" />
<xsl:key name="artists_albums"
         match="mp3"
         use="concat(artist/displayname, ' ',
                     album/displayname)" />

<xsl:template match="mp3list">
  <html>
    <head>
    </head>
    <body>
      <xsl:for-each
           select="mp3[count(. | key('artists', artist/displayname)[1]) =
1]">
        <xsl:sort select="artist/displayname" />
        <xsl:variable name="top_artist" select="artist/displayname" />
        <h1><xsl:value-of select="$top_artist" /></h1>

        <xsl:variable
             name="album_items"
             select="key('artists', artist/displayname)" />
        <xsl:for-each select="$album_items[generate-id() =
generate-id(key('artists_albums', concat(artist/displayname, ' ',
album/displayname))[1])]">
          <xsl:sort select="album/displayname" />
          <xsl:call-template name="album_title"/>
          <xsl:call-template name="album_content"/>
        </xsl:for-each>
      </xsl:for-each>

      <xsl:call-template name="page_footer"/>

    </body>
  </html>
</xsl:template>

<xsl:template name="album_title">
    <xsl:element name="h3">
    <xsl:attribute name="id"><xsl:value-of
select="concat('h',generate-id(.))" /></xsl:attribute>
      <xsl:attribute name="class">header</xsl:attribute>
      <xsl:value-of select="album/displayname" />
    </xsl:element>
</xsl:template>

<xsl:template name="album_content">
    <xsl:element name="div">
      <xsl:attribute name="id"><xsl:value-of
select="concat('d',generate-id(.))" /></xsl:attribute>
      <xsl:attribute name="class">details</xsl:attribute>
      <table>
        <tr>
          <th>No.</th>
          <th>Title</th>
          <th>Length</th>
          <th>bitrate</th>
          <th>vbr</th>
        </tr>
        <xsl:for-each select="key('albums', album/displayname)">
          <xsl:sort select="trackindex" data-type="number"/>
        <tr>
          <xsl:call-template name="highlighter"/>
          <td><xsl:number format="01 " value="trackindex"/></td>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="length"/></td>
          <td><xsl:value-of select="bitrate"/></td>
          <td><xsl:value-of select="vbr"/></td>
        </tr>
        </xsl:for-each>
      </table>
    </xsl:element>
</xsl:template>

<xsl:template name="highlighter">
  <td>
    <xsl:if test="../../artist/displayname != artist/displayname">
    <xsl:attribute name="class">fadeout</xsl:attribute>
    abc
  </xsl:if>
  </td>
</xsl:template>

<xsl:template name="page_footer">
  <hr/>
</xsl:template>

</xsl:stylesheet>
-------[END SOURCE XSL]--------



-------[BEGIN SOURCE XML]--------
<?xml version="1.0"?>
<mp3info creationdate="24/10/2004 11:18:52">
  <mp3list>
    <mp3>
      <title>Why Go</title>
      <album>
        <displayname>Ten</displayname>
      </album>
      <artist>
        <displayname>Pearl Jam</displayname>
      </artist>
      <year>
        <displayname>1992</displayname>
      </year>
      <genres>
        <genre>
          <displayname>Grunge</displayname>
        </genre>
      </genres>
      <trackindex>1</trackindex>
    </mp3>
    <mp3>
      <title>Black</title>
      <album>
        <displayname>Ten</displayname>
      </album>
      <artist>
        <displayname>Pearl Jam</displayname>
      </artist>
      <year>
        <displayname>1992</displayname>
      </year>
      <genres>
        <genre>
          <displayname>Grunge</displayname>
        </genre>
      </genres>
      <trackindex>2</trackindex>
    </mp3>
    <mp3>
      <title>Silver Dawn</title>
      <album>
        <displayname>Earth Volume 2</displayname>
      </album>
      <artist>
        <displayname>Artemis</displayname>
      </artist>
      <year>
        <displayname>1997</displayname>
      </year>
      <genres>
        <genre>
          <displayname>Drum &amp; Bass</displayname>
        </genre>
      </genres>
      <trackindex>2</trackindex>
    </mp3>
    <mp3>
      <title>Artifical Life</title>
      <album>
        <displayname>Earth Volume 2</displayname>
      </album>
      <artist>
        <displayname>Odyssey</displayname>
      </artist>
      <year>
        <displayname>1997</displayname>
      </year>
      <genres>
        <genre>
          <displayname>Drum &amp; Bass</displayname>
        </genre>
      </genres>
      <trackindex>3</trackindex>
    </mp3>
    <mp3>
      <title>Fictions</title>
      <album>
        <displayname>Earth Volume 2</displayname>
      </album>
      <artist>
        <displayname>Rollercone</displayname>
      </artist>
      <year>
        <displayname>1997</displayname>
      </year>
      <genres>
        <genre>
          <displayname>Drum &amp; Bass</displayname>
        </genre>
      </genres>
      <trackindex>1</trackindex>
    </mp3>
  </mp3list>
</mp3info>
-------[END SOURCE XML]--------



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