Hi I am pretty new to XSLT usage (without using xsl:for-each which might be the culprit) and am running into an issue trying to get sorting going for the party element to function as expected.
I have an XML document containing:
  enter <?xml version="1.0" encoding="UTF-8"?>            <presidents xmlnsxsi="http//www.w3.org/2001/XMLSchema-instance"          xsinoNamespaceSchemaLocation="http//www.du.edu/~mschwart/xml/president.xsd"          date="2012-08-18">          <president>              <number>1</number>              <name>George Washington</name>              <birthday>2/22/1732</birthday>              <took_office>1789-04-30</took_office>              <left_office>1797-03-04</left_office>              <party>no party</party>              <term>                  <number>1</number>                  <vice_president>John Adams</vice_president>              </term>              <term>                  <number>2</number>                  <vice_president>John Adams</vice_president>              </term>          </president>            <president>              <number>2</number>              <name>John Adams</name>              <birthday>10/30/1735</birthday>              <took_office>1797-03-04</took_office>              <left_office>1801-03-04</left_office>              <party>Federalist</party>              <term>                  <number>3</number>                  <vice_president>Thomas Jefferson</vice_president>              </term>          </president>          <president>              <number>3</number>              <name>Thomas Jefferson</name>              <birthday>4/13/1743</birthday>              <took_office>1801-03-04</took_office>              <left_office>1809-03-04</left_office>              <party>Democratic-Republican</party>              <term>                  <number>4</number>                  <vice_president>Aaron Burr</vice_president>              </term>              <term>                  <number>5</number>                  <vice_president>George Clinton</vice_president>              </term>          </president>          <president>              <number>4</number>              <name>James Madison</name>              <birthday>3/16/1751</birthday>              <took_office>1809-03-04</took_office>              <left_office>1817-03-04</left_office>              <party>Democratic-Republican</party>              <term>                  <number>6</number>                  <vice_president>George Clinton</vice_president>              </term>              <term>                  <number>7</number>                  <vice_president>Elbridge Gerry</vice_president>              </term>          </president></presidents>      And an XSLT document where I am added items for other requests, but am now required to sort the data by party:
  <xsl:template match="/">      <html>          <head>              <link rel="stylesheet" type="text/css" href="president_table.css" />              <title>Table of US Presidents</title>          </head>          <body>              <h1>Table of US Presidents</h1>              <table>              <tr>                  <th>Name</th>                  <th>Birthday</th>                  <th>Took Office</th>                  <th>Left Ofice</th>                  <th>Party</th>                  <th>Vice President(s)</th>              </tr>              <xsl:apply-templates select="presidents">                  <xsl:sort select="party" order="descending"/>                  </xsl:apply-templates>              </table>          </body>      </html>  </xsl:template>  <xsl:template match="president">      <tr>          <td><xsl:apply-templates select="name"/></td>          <td><xsl:apply-templates select="birthday"/></td>          <td><xsl:apply-templates select="took_office"/></td>          <td><xsl:apply-templates select="left_office"/></td>          <td>              <xsl:apply-templates select="party">              </xsl:apply-templates>              <xsl:value-of select="party"/>          </td>          <td>              <xsl:apply-templates select="term"/>          </td>      </tr>  </xsl:template>  <xsl:template match="term">      <xsl:number value="position()" format="1. " />      <xsl:value-of select="vice_president" /><br />  </xsl:template>  <xsl:template match="party">      <xsl:choose>          <xsl:when test=". = 'Federalist'">              <xsl:attribute name="class">Federalist</xsl:attribute>          </xsl:when>          <xsl:when test=". = 'Democratic-Republican'">              <xsl:attribute name="class">Democratic-Republican</xsl:attribute>          </xsl:when>          <xsl:when test=". = 'Democratic'">              <xsl:attribute name="class">Democratic</xsl:attribute>          </xsl:when>          <xsl:when test=". = 'Republican'">              <xsl:attribute name="class">Republican</xsl:attribute>          </xsl:when>          <xsl:when test=". = 'Whig'">              <xsl:attribute name="class">Whig</xsl:attribute>          </xsl:when>          <xsl:otherwise>              <xsl:attribute name="class">noparty</xsl:attribute>          </xsl:otherwise>      </xsl:choose>  </xsl:template>      I have searched around and nothing specific to what is happening exactly and I have followed instructions from a number of examples in attempt to get things sorted.
Thanks for any assistance in advance!!
No comments:
Post a Comment