troubleshooting Question

Q: XSL - Using For-Each, Choose functions

Avatar of Jammerules
Jammerules asked on
HTMLXML
8 Comments2 Solutions331 ViewsLast Modified:
Experts,

Noob question - I am trying to do a simple exercise with For-Each and Choose functions of XSL. I want to select a particular value based on a condition. Here are my XSL and XML codes:
XSL:
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"> 
  <xsl:output method="html"/>
    
  <xsl:template match="/">
      <html>
          <table>              
              <tr>
                  <td bgcolor="lightgray"> Republican President </td>
                  <td>
                      <xsl:for-each select="Profiles/Profile"> 
                          <xsl:choose>
                              <xsl:when test="./Party='GOP'">
                                 <xsl:value-of select="./FirstName"/>
                                 <xsl:text> - (2001-2009) </xsl:text>
                              </xsl:when> 
                              <xsl:otherwise>
                                  <xsl:value-of select="./FirstName"/>
                                  <xsl:text> DEM </xsl:text>
                              </xsl:otherwise>
                          </xsl:choose>   
                      </xsl:for-each>
                  </td>
              </tr>
              <!--
              <tr>
                  <td> Democratic President </td>
                  <td bgcolor="gray">
                      <xsl:for-each select="Profiles/Profile">
                          <xsl:if test="./Party='DEM'">
                              <xsl:value-of select="./FirstName"/>
                          </xsl:if>
                      </xsl:for-each>
                  </td>
              </tr>  
              -->                     
          </table>
      </html>
  </xsl:template> 

</xsl:stylesheet>
 
XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="XSLTFile_ex1.xslt"?>
<Profiles>
      <Profile>
          <Salutation>Mr. </Salutation>  
          <FirstName>Barack</FirstName>
          <LastName>Obama
              <Suffixes>
                  <Suffix></Suffix> 
              </Suffixes>
          </LastName>
          <Party>DEM</Party>

          <Salutation>Mr. </Salutation>
          <FirstName>George</FirstName>
          <LastName>
              Bush
              <Suffixes>
                  <Suffix>Sr</Suffix>
              </Suffixes>
          </LastName>
          <Party>GOP</Party>

      </Profile>
</Profiles>

I am unable to get the required result. Where am I going wrong?
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)
Information Architect
Join our community to see this answer!
Unlock 2 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros