Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - Logic Problem in xsl

 
Thread Tools Search this Thread
Old 05-25-2006, 11:49 PM   #1
Default Logic Problem in xsl


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
  Reply With Quote
Old 05-26-2006, 02:41 PM   #2
Joe Kesselman
 
Posts: n/a
Default Re: Logic Problem in xsl

Sounds like a standard grouping problem:
http://www.dpawson.co.uk/xsl/sect2/N4486.html

(I believe XSLT 2.0 is supposed to make grouping a bit easier.)
  Reply With Quote
Old 05-26-2006, 10:16 PM   #3
kevinmarren@yahoo.ie
 
Posts: n/a
Default Re: Logic Problem in xsl

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"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-comslt">
<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


  Reply With Quote
Old 05-28-2006, 03:23 PM   #4
GeezerButler
 
Posts: n/a
Default Re: Logic Problem in xsl

Thanks, got it to work

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump