|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Can't get predicates working.
Hi Marco,
Please try this XSL.. (I am assuming, you wish to
generate HTML)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:template match="/company">
<html>
<head>
<title/>
</head>
<body>
<xsl:apply-templates select="division" />
</body>
</html>
</xsl:template>
<xsl:template match="division">
<table border="1">
<th>
<td>
Division Name = <xsl:value-of select="@DID"
/>
</td>
</th>
<xsl:for-each select="projects/project">
<tr>
<td>PID=<xsl:value-of select="@PID" /></td>
<td>PNAME=<xsl:value-of select="PNAME"
/></td>
<td>BUDGET=<xsl:value-of select="BUDGET"
/></td>
</tr>
<xsl:for-each select="assigns/assign">
<tr>
<td>EID=<xsl:value-of select="@refEID" /></td>
<td>ENAME=<xsl:value-of
select="ancestor::division[1]/employees/employee[@EID
= current()/@refEID]/ENAME" /></td>
<td>OFFICE=<xsl:value-of
select="ancestor::division[1]/employees/employee[@EID
= current()/@refEID]/OFFICE" /></td>
<td>HOURS=<xsl:value-of select="HOURS" /></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
My solution differs from Aron's in writing style. Aron
has used xsl:apply-templates (which is sometimes
called push processing).
While I have used xsl:for-each (which is sometimes
called pull processing) ..
We may even mix these two styles of programming
depending on requirement..
Regards,
Mukul
--- Marco Mastrocinque <mmfive@xxxxxxxxxxxxxxx> wrote:
>
> Hi All,
> I'm having trouble with a predicate selection
> (i.e. a conditional
> selection). For the following xml structure.
>
> <company>
> <division DID="XXX">
> <projects>
> <project PID='XYZ'> (Project ID)
> <PNAME>Some Name</PNAME> (Project Name)
> <BUDGET>111</BUDGET>
> <assigns>
> <assign refEID='XXX000'>
> <HOURS>12</HOURS>
> </assign>
> <assign refEID='XXX001'>
> <HOURS>78</HOURS>
> </assign>
> <assigns>
> </project>
> <project PID='XY1'>
> <PNAME>Some OtherName</PNAME>
> <BUDGET>112</BUDGET>
> <assigns>
> <assign refEID='XXX000'>
> <HOURS>34</HOURS>
> </assign>
> <assign refEID='XXX002'>
> <HOURS>1234</HOURS>
> </assign>
> <assigns>
> </project>
> Etc..
> </projects>
> <employees>
> <employee EID='XXX000'>
> <ENAME>Joe Blow</ENAME>
> <OFFICE>1204</OFFICE>
> <BIRTHDATE>1924-08-01</BIRTHDATE>
> </employee>
> <employee EID='XXX001'>
> <ENAME>Joe Smith</ENAME>
> <OFFICE>1203</OFFICE>
> <BIRTHDATE>1930-08-01</BIRTHDATE>
> </employee>
> <employee EID='XXX002'>
> <ENAME>Joe Jerry</ENAME>
> <OFFICE>0003</OFFICE>
> <BIRTHDATE>1930-08-01</BIRTHDATE>
> </employee>
> </employees>
> </division>
> Etc.. (there are multiple divisions with the same
> structure, employees can
> only work for one division and a project only
> belongs to a single division
> )
> </company>
>
> I won't to have a table that shows PID, PNAME,
> BUDGET and then the employee
> EID (unique identifier), the employee name (ENAME),
> OFFICE and HOURS spent
> on each project.
>
> The output I won't is
>
> Division Name = XXX
> PID='XYZ' PNAME=Some Name BUDGET=111
> EID= XXX000 ENAME= Joe Blow OFFICE=1204 HOURS=12
> EID= XXX001 ENAME= Joe Smith OFFICE=1203 HOURS=78
>
> PID=' XY1' PNAME= Some OtherName BUDGET=112
> EID= XXX000 ENAME= Joe Blow OFFICE=1204 HOURS=34
> EID= XXX002 ENAME= Joe Jerry OFFICE=0003 HOURS=1234
>
> This above output is done for every division.
>
> I have to match the refEID attribute of assign
> element with the EID
> attribute of employee element. Then out the EID
> (refEID), with the ENAME and
> OFFICE elements, while looping the projects for each
> division. I know it is
> a conditional selection (I think?), but I just can't
> get working.
>
>
> Thanks Marco Mastrocinque
>
>
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








