title: xsl:choose being applied to all elements, not just the ones I want
body: <p>Firstly I'll post ALL my code:</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;!DOCTYPE catalog SYSTEM "test.dtd"&gt;
  
  &lt;?xml-stylesheet type="text/xsl" href="test.xsl"?&gt;
  &lt;catalog&gt;
      &lt;product category="art" id="id_001"&gt;
          &lt;title&gt;Blue Sculpture&lt;/title&gt;
          &lt;price currency="AUS"&gt;2000&lt;/price&gt;
          &lt;creation_date&gt;
              &lt;day&gt;11&lt;/day&gt;
              &lt;month&gt;08&lt;/month&gt;
              &lt;year format="yyyy"&gt;2014&lt;/year&gt;
          &lt;/creation_date&gt;
          &lt;weight unit="kilogram"&gt;2&lt;/weight&gt;
          &lt;color&gt;Green&lt;/color&gt;
          &lt;description&gt;A beutiful Green Sculpture&lt;/description&gt;
      &lt;/product&gt;
      &lt;product category="ovenware" id="id_002"&gt;
          &lt;title&gt;Red Pie Dish&lt;/title&gt;
          &lt;price currency="AUS"&gt;400&lt;/price&gt;
          &lt;creation_date&gt;
              &lt;day&gt;5&lt;/day&gt;
              &lt;month&gt;11&lt;/month&gt;
              &lt;year format="yyyy"&gt;2013&lt;/year&gt;
          &lt;/creation_date&gt;
          &lt;weight unit="kilogram"&gt;5&lt;/weight&gt;
          &lt;color&gt;Red&lt;/color&gt;
          &lt;description&gt;Versatile Pie Dish!&lt;/description&gt;
      &lt;/product&gt;
      &lt;product category="dinner_set" id="id_003"&gt;
          &lt;title&gt;Blue Sculpture&lt;/title&gt;
          &lt;price currency="AUS"&gt;2000&lt;/price&gt;
          &lt;creation_date&gt;
              &lt;day&gt;11&lt;/day&gt;
              &lt;month&gt;08&lt;/month&gt;
              &lt;year format="yyyy"&gt;2014&lt;/year&gt;
          &lt;/creation_date&gt;
          &lt;weight unit="ton"&gt;2&lt;/weight&gt;
          &lt;color&gt;Green&lt;/color&gt;
          &lt;description&gt;A beutiful Green Sculpture&lt;/description&gt;
      &lt;/product&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>XSL:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:template match="/"&gt;
  &lt;html&gt;
  &lt;link rel="stylesheet" type="text/css" href="test.css" /&gt;
  &lt;p&gt;Artworks&lt;/p&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;th&gt;Title&lt;/th&gt;
      &lt;th&gt;Price&lt;/th&gt;
      &lt;th&gt;Creation Date&lt;/th&gt;
      &lt;th&gt;Weight&lt;/th&gt;
      &lt;th&gt;Color&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
      &lt;xsl:for-each select="catalog/product[@category='art']"&gt;
          &lt;xsl:sort select="@id" data-type="number"/&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt;
      &lt;td&gt;
          &lt;span&gt;&amp;#36;&lt;/span&gt;
          &lt;xsl:value-of select="price"/&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;xsl:value-of select="creation_date/day"/&gt;
          &lt;span&gt;&amp;#47;&lt;/span&gt;
          &lt;xsl:value-of select="creation_date/month"/&gt;
          &lt;span&gt;&amp;#47;&lt;/span&gt;
          &lt;xsl:value-of select="creation_date/year"/&gt;
      &lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="weight"/&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="//weight[@unit = 'gram']"&gt;
                  &lt;span&gt;g&lt;/span&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:when test="//weight[@unit = 'kilogram']"&gt;
                  &lt;span&gt;&amp;#32;Kg&lt;/span&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:if test="//weight &gt; 1"&gt;
                  &lt;span&gt;&amp;#32;Tonnes&lt;/span&gt;
                  &lt;/xsl:if&gt;
                  &lt;xsl:if test="//weight &amp;lt;= 1"&gt;
                  &lt;span&gt;&amp;#32;Ton&lt;/span&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="color"/&gt;&lt;/td&gt;
      &lt;td class="description"&gt;&lt;xsl:value-of select="description"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/xsl:for-each&gt;
  &lt;/table&gt;
  
  &lt;p&gt;Ovenware&lt;/p&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;th&gt;Title&lt;/th&gt;
      &lt;th&gt;Price&lt;/th&gt;
      &lt;th&gt;Creation Date&lt;/th&gt;
      &lt;th&gt;Weight&lt;/th&gt;
      &lt;th&gt;Color&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
      &lt;xsl:for-each select="catalog/product[@category='ovenware']"&gt;
          &lt;xsl:sort select="id"/&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt;
      &lt;td&gt;
          &lt;span&gt;&amp;#36;&lt;/span&gt;
          &lt;xsl:value-of select="price"/&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;xsl:value-of select="creation_date/day"/&gt;
          &lt;span&gt;&amp;#47;&lt;/span&gt;
          &lt;xsl:value-of select="creation_date/month"/&gt;
          &lt;span&gt;&amp;#47;&lt;/span&gt;
          &lt;xsl:value-of select="creation_date/year"/&gt;
      &lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="weight"/&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="//weight[@unit = 'gram']"&gt;
                  &lt;span&gt;g&lt;/span&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:when test="//weight[@unit = 'kilogram']"&gt;
                  &lt;span&gt;&amp;#32;Kg&lt;/span&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:if test="//weight &gt; 1"&gt;
                  &lt;span&gt;&amp;#32;Tonnes&lt;/span&gt;
                  &lt;/xsl:if&gt;
                  &lt;xsl:if test="//weight &amp;lt;= 1"&gt;
                  &lt;span&gt;&amp;#32;Ton&lt;/span&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="color"/&gt;&lt;/td&gt;
      &lt;td class="description"&gt;&lt;xsl:value-of select="description"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/xsl:for-each&gt;
  &lt;/table&gt;
  
  &lt;p&gt;Dinner Set's&lt;/p&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;th&gt;Title&lt;/th&gt;
      &lt;th&gt;Price&lt;/th&gt;
      &lt;th&gt;Creation Date&lt;/th&gt;
      &lt;th&gt;Weight&lt;/th&gt;
      &lt;th&gt;Color&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
      &lt;xsl:for-each select="catalog/product[@category='dinner_set']"&gt;
          &lt;xsl:sort select="id"/&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt;
      &lt;td&gt;
          &lt;span&gt;&amp;#36;&lt;/span&gt;
          &lt;xsl:value-of select="price"/&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;xsl:value-of select="creation_date/day"/&gt;
          &lt;span&gt;&amp;#47;&lt;/span&gt;
          &lt;xsl:value-of select="creation_date/month"/&gt;
          &lt;span&gt;&amp;#47;&lt;/span&gt;
          &lt;xsl:value-of select="creation_date/year"/&gt;
      &lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="weight"/&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="//weight[@unit = 'gram']"&gt;
                  &lt;span&gt;g&lt;/span&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:when test="//weight[@unit = 'kilogram']"&gt;
                  &lt;span&gt;&amp;#32;Kg&lt;/span&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:if test="//weight &gt; 1"&gt;
                  &lt;span&gt;&amp;#32;Tonnes&lt;/span&gt;
                  &lt;/xsl:if&gt;
                  &lt;xsl:if test="//weight &amp;lt;= 1"&gt;
                  &lt;span&gt;&amp;#32;Ton&lt;/span&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/td&gt;
      &lt;td&gt;&lt;xsl:value-of select="color"/&gt;&lt;/td&gt;
      &lt;td class="description"&gt;&lt;xsl:value-of select="description"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/xsl:for-each&gt;
  &lt;/table&gt;
  &lt;/html&gt;
  &lt;/xsl:template&gt;
  
  
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And just incase you want to have a look, my DTD:</p>
  
  <pre><code>&lt;!ELEMENT catalog (product+)&gt;
  &lt;!ELEMENT product (title?, price, creation_date?, weight?, color, description?)&gt;
  &lt;!ELEMENT creation_date (day, month, year)&gt;
  
  &lt;!ATTLIST product id ID #REQUIRED&gt;
  &lt;!ATTLIST product category (art|dinner_set|ovenware) "art"&gt;
  &lt;!ATTLIST price currency (AUS|USA) "AUS"&gt;
  &lt;!ATTLIST weight unit (gram|kilogram|ton) "gram"&gt;
  &lt;!ATTLIST year format (yy|yyyy) "yy"&gt;
  
  
  &lt;!ELEMENT id (#PCDATA)&gt;
  &lt;!ELEMENT title (#PCDATA)&gt;
  &lt;!ELEMENT price (#PCDATA)&gt;
  &lt;!ELEMENT day (#PCDATA)&gt;
  &lt;!ELEMENT month (#PCDATA)&gt;
  &lt;!ELEMENT year (#PCDATA)&gt;
  &lt;!ELEMENT weight (#PCDATA)&gt;
  &lt;!ELEMENT color (#PCDATA)&gt;
  &lt;!ELEMENT description (#PCDATA)&gt;.
  </code></pre>
  
  <p>And the Css, so you guys can run this properly :)</p>
  
  <pre><code>body{
      background-color: #fff;
  
  }
  table{
      border-collapse:collapse;
      border-spacing:0;
      padding: 10px;
      width: 100%;
      overflow: hidden;
  }
  td{
      font-family:Arial, sans-serif;
      font-size:14px;
      padding:10px 5px;
      overflow:hidden;
      word-break:normal;
      min-width: 80px;
      text-align: center;
      background-color: #E0E5DF;
      border-bottom: 2px solid #f6f6f6;
      border-top: 2px solid #f6f6f6;
  }
  th{
      font-family:Arial, sans-serif;
      font-size:14px;
      font-weight:normal;
      padding:10px 5px;
      overflow:hidden;
      word-break:normal;
      border-top: 4px solid #32517F;
      border-bottom: 2px solid #f6f6f6;
      background-color: #64A2FF;
  }
  tr:hover td{
      background-color: #81BDF7;
  }
  .description{
      width: 20%;
  }
  </code></pre>
  
  <p>Okay so if you post all these in a folder and name them all "test.(whatever the extension is)". So test.xml, test.dtd ect.</p>
  
  <p>So the real problem is this bit of code here:</p>
  
  <pre><code>&lt;td&gt;&lt;xsl:value-of select="weight"/&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="//weight[@unit = 'gram']"&gt;
              &lt;span&gt;g&lt;/span&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="//weight[@unit = 'kilogram']"&gt;
              &lt;span&gt;&amp;#32;Kg&lt;/span&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:if test="//weight &gt; 1"&gt;
              &lt;span&gt;&amp;#32;Tonnes&lt;/span&gt;
              &lt;/xsl:if&gt;
              &lt;xsl:if test="//weight &amp;lt;= 1"&gt;
              &lt;span&gt;&amp;#32;Ton&lt;/span&gt;
              &lt;/xsl:if&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>What it's meant to do is check the attribute 'unit', and depending on it's value is then append a g, kg or ton to the end of the actual weight. This part works rather well. The problem is that it uses the first  and applies it to all three tables.</p>
  
  <p>So for exampl in my xml if the first products weight, attribute unit is set to kg, then every product in all the tables is set to kg.</p>
  
  <p>Hope i have explained this well enough and it actually makes sense. I posted all the code so you guys could run it for yourselves, seemed easier that trying to explain it exzactly.</p>
  
  <p>Thanks,</p>
  
  <p>Joel</p>