Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL: Changing XSL variable for backgound color

Status
Not open for further replies.

Bysse

Programmer
May 27, 2003
1
SE
Hi all!

I have this XML problem that I dont know how to solve. I want to have a table where each other row have different color.
Example:
white
black
white
black

the xml I have to work with is like this:
<pack>
<service>
<service>
<service>
</pack>
<pack>
<service>
<service>
</pack>

In my table I want the name of the service, I have started to do two xsl:for-each, one for packs and one for services. the number of packs or service is dynamic.

Does someone have a good XSL solution for this?

Regards,
Andreas
 
Something like this does the trick:
Code:
  <xsl:template match=&quot;root_or_whatever&quot;>
    <TABLE>
      <xsl:for-each select=&quot;pack/service&quot;>
        <xsl:variable name=&quot;colornumber&quot;>
          <xsl:value-of select=&quot;position() mod 4&quot;/>
        </xsl:variable>
        <tr>
          <xsl:attribute name=&quot;bgcolor&quot;>
            <xsl:call-template name=&quot;colorvalue&quot;>
              <xsl:with-param name=&quot;number&quot; select=&quot;$colornumber&quot;/>
            </xsl:call-template>
          </xsl:attribute>
          <td>
            <xsl:value-of select=&quot;name&quot;/>
          </td>
        </tr>
      </xsl:for-each>
    </TABLE>
  </xsl:template>

  <xsl:template name=&quot;colorvalue&quot;>
    <xsl:param name=&quot;number&quot;/>
    <xsl:choose>
      <xsl:when test=&quot;$number=0&quot;>
        <xsl:value-of select=&quot;'RED'&quot;/>
      </xsl:when>
      <xsl:when test=&quot;$number=1&quot;>
        <xsl:value-of select=&quot;'WHITE'&quot;/>
      </xsl:when>
      <xsl:when test=&quot;$number=2&quot;>
        <xsl:value-of select=&quot;'BLACK'&quot;/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select=&quot;'BLUE'&quot;/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top