Logic Problem in xsl

Discussion in 'XML' started by GeezerButler, May 25, 2006.

  1. GeezerButler

    GeezerButler Guest

    Hi,
    I want to convert the following xml file into html using xsl:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="projects.xsl"?>
    <Employees>
    <Employee>
    <Name>Aseem Sharma</Name>
    <EmployeeId>119370</EmployeeId>
    <Project>Metlife</Project>
    <Designation rank="d">Programmer Analyst</Designation>
    </Employee>
    <Employee>
    <Name>Aiman Ashraf</Name>
    <EmployeeId>119372</EmployeeId>
    <Project>Metlife</Project>
    <Designation rank="d">Programmer Analyst</Designation>
    </Employee>
    <Employee>
    <Name>S Krishnan</Name>
    <EmployeeId>143370</EmployeeId>
    <Project>Metlife</Project>
    <Designation rank="a">Project Manager</Designation>
    </Employee>
    <Employee>
    <Name>Aaditya Thakur</Name>
    <EmployeeId>118736</EmployeeId>
    <Project>Coors</Project>
    <Designation rank="d">Programmer Analyst</Designation>
    </Employee>
    <Employee>
    <Name>Ankur Srivastava</Name>
    <EmployeeId>129370</EmployeeId>
    <Project>Coors</Project>
    <Designation rank="d">Programmer Analyst</Designation>
    </Employee>
    <Employee>
    <Name>Rohan Taneja</Name>
    <EmployeeId>126660</EmployeeId>
    <Project>Coors</Project>
    <Designation rank="c">Associate</Designation>
    </Employee>
    <Employee>
    <Name>Purnima Raghunath</Name>
    <EmployeeId>113330</EmployeeId>
    <Project>Coors</Project>
    <Designation rank="a">Project Manager</Designation>
    </Employee>
    <Employee>
    <Name>Trisha Singh</Name>
    <EmployeeId>112340</EmployeeId>
    <Project>Wachovia</Project>
    <Designation rank="d">Programmer Analyst</Designation>
    </Employee>
    <Employee>
    <Name>Rakesh Menon</Name>
    <EmployeeId>103450</EmployeeId>
    <Project>Metlife</Project>
    <Designation rank="c">Associate</Designation>
    </Employee>
    <Employee>
    <Name>Sachin Doshi</Name>
    <EmployeeId>145670</EmployeeId>
    <Project>Metlife</Project>
    <Designation rank="b">Senior Associate</Designation>
    </Employee>
    </Employees>

    The html should show a table for each PROJECT with their respective
    employees.
    So, there'll be 3 tables (Metlife,Coors,Wachovia). The problem is that
    I cannot hard code the name of the project anywhere in xsl as more
    nodes with other project names can get added to the xml file.
    Could anyone give me a hint on how to go about this.

    Any help would be super appreciated.

    Thanks
     
    GeezerButler, May 25, 2006
    #1
    1. Advertising

  2. Joe Kesselman, May 26, 2006
    #2
    1. Advertising

  3. GeezerButler

    Guest

    Hi try this not exactly what your looking for but might give you an
    idea:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt">
    <xsl:template match="/">
    <xsl:variable name="SortedRows">
    <xsl:for-each select="/Root/Table/Row">
    <xsl:sort select="Group"/>
    <xsl:copy-of select="."/>
    </xsl:for-each>
    </xsl:variable>
    <html>
    <table border="1">
    <tr>
    <th>First Name</th>
    <th>Second Name</th>
    <th>Group</th>
    <th>Next</th>
    </tr>

    <xsl:for-each select="msxml:node-set($SortedRows)/*">
    <tr>
    <td><xsl:value-of select="./FirstName"/></td>
    <td><xsl:value-of select="./SecondName"/></td>
    <td><xsl:value-of select="./Group"/></td>
    <td><xsl:value-of select="following-sibling::*/SecondName"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    GeezerButler wrote:
    > Hi,
    > I want to convert the following xml file into html using xsl:
    >
    > <?xml version="1.0"?>
    > <?xml-stylesheet type="text/xsl" href="projects.xsl"?>
    > <Employees>
    > <Employee>
    > <Name>Aseem Sharma</Name>
    > <EmployeeId>119370</EmployeeId>
    > <Project>Metlife</Project>
    > <Designation rank="d">Programmer Analyst</Designation>
    > </Employee>
    > <Employee>
    > <Name>Aiman Ashraf</Name>
    > <EmployeeId>119372</EmployeeId>
    > <Project>Metlife</Project>
    > <Designation rank="d">Programmer Analyst</Designation>
    > </Employee>
    > <Employee>
    > <Name>S Krishnan</Name>
    > <EmployeeId>143370</EmployeeId>
    > <Project>Metlife</Project>
    > <Designation rank="a">Project Manager</Designation>
    > </Employee>
    > <Employee>
    > <Name>Aaditya Thakur</Name>
    > <EmployeeId>118736</EmployeeId>
    > <Project>Coors</Project>
    > <Designation rank="d">Programmer Analyst</Designation>
    > </Employee>
    > <Employee>
    > <Name>Ankur Srivastava</Name>
    > <EmployeeId>129370</EmployeeId>
    > <Project>Coors</Project>
    > <Designation rank="d">Programmer Analyst</Designation>
    > </Employee>
    > <Employee>
    > <Name>Rohan Taneja</Name>
    > <EmployeeId>126660</EmployeeId>
    > <Project>Coors</Project>
    > <Designation rank="c">Associate</Designation>
    > </Employee>
    > <Employee>
    > <Name>Purnima Raghunath</Name>
    > <EmployeeId>113330</EmployeeId>
    > <Project>Coors</Project>
    > <Designation rank="a">Project Manager</Designation>
    > </Employee>
    > <Employee>
    > <Name>Trisha Singh</Name>
    > <EmployeeId>112340</EmployeeId>
    > <Project>Wachovia</Project>
    > <Designation rank="d">Programmer Analyst</Designation>
    > </Employee>
    > <Employee>
    > <Name>Rakesh Menon</Name>
    > <EmployeeId>103450</EmployeeId>
    > <Project>Metlife</Project>
    > <Designation rank="c">Associate</Designation>
    > </Employee>
    > <Employee>
    > <Name>Sachin Doshi</Name>
    > <EmployeeId>145670</EmployeeId>
    > <Project>Metlife</Project>
    > <Designation rank="b">Senior Associate</Designation>
    > </Employee>
    > </Employees>
    >
    > The html should show a table for each PROJECT with their respective
    > employees.
    > So, there'll be 3 tables (Metlife,Coors,Wachovia). The problem is that
    > I cannot hard code the name of the project anywhere in xsl as more
    > nodes with other project names can get added to the xml file.
    > Could anyone give me a hint on how to go about this.
    >
    > Any help would be super appreciated.
    >
    > Thanks
     
    , May 26, 2006
    #3
  4. GeezerButler

    GeezerButler Guest

    Thanks, got it to work
     
    GeezerButler, May 28, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Flood
    Replies:
    0
    Views:
    1,033
    Kevin Flood
    Sep 8, 2004
  2. Kevin Flood
    Replies:
    1
    Views:
    2,769
    Kevin Flood
    Sep 13, 2004
  3. Klaus Friese
    Replies:
    0
    Views:
    481
    Klaus Friese
    Nov 22, 2004
  4. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
  5. spike
    Replies:
    8
    Views:
    1,498
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page