xsl-list
[Top] [All Lists]

RE: Displaying multiple instances of the same tag

2004-06-13 13:17:43
Hmm... no bother. Answering questions and learning answers is what I ( and 
presumably we ) are here for.

I think your problem is with context. If you want to put all of the quotes 
above the table, then your context will be "/" which means that the path to all 
of the quotes is not "quote" but instead "catalog/cd/quote". If you want to put 
the specific quotes for a cd inside of a cell of the table then you will be in 
the for-each which changes the context to "catalog/cd", and your relative path 
will be "quote".

Here is your code revised:

<?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="html" encoding="UTF-8" indent="yes"/>

  <xsl:template match="/">
<html>
<body>

<ol>
<xsl:for-each select="catalog/cd/quote">
  <li><xsl:value-of select="."/></li>
</xsl:for-each>
</ol>

  <h2>Your Selection</h2>
  <table border="1">
  <tr bgcolor="#9acd32">
    <th>Title</th>
    <th>Artist</th>
    <th>Quotes</th>
  </tr>
  <xsl:for-each select="catalog/cd">
  <tr>
    <td><xsl:value-of select="title"/></td>
    <xsl:choose>
      <xsl:when test="artist = 'Book'">
      <td bgcolor="#ff00ff">
        <xsl:value-of select="name"/>
      </td>
      </xsl:when>
      <xsl:when test="artist = 'Journal Article'">
      <td bgcolor="#cccccc">
        <xsl:value-of select="journal"/>
      </td>
      </xsl:when>
      <xsl:otherwise>
        <td><xsl:value-of select="artist"/></td>
      </xsl:otherwise>
    </xsl:choose>
    <td>
      <xsl:choose>
        <xsl:when test="quote">
      <ol>
        <xsl:for-each select="quote">
        <li><xsl:value-of select="."/></li>
        </xsl:for-each>
      </ol>
        </xsl:when>
        <xsl:otherwise>
          &#160;
        </xsl:otherwise>
      </xsl:choose>

    </td>
  </tr>
  </xsl:for-each>
  </table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


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