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

RE: Displaying multiple instances of the same tag

Subject: RE: Displaying multiple instances of the same tag
From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx>
Date: Sun, 13 Jun 2004 13:17:43 -0700
xsl multiple instances
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>

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.