HI Hiren.
Is your XML decided?? because this doesnt look very structured to me.You are
giving columns and rows in a different element set. You requirement tells me
that for example
"Gross" and "9 Million " are like name value pair . Your XML has these
information loosly held. when it was supposed to be together.
A better design ( if your xml is not decided ) would be,
<?xml-stylesheet type="text/xsl" href="CompetitorReport.xsl"?>
<Report>
<Header type = "reportheader">
Competitor
</Header>
<Body>
<Title>Corporate Info</Title>
<corporate-info>
<Company-Financials>
<competetor name = "competetor1">
<gross>9 Million</gross>
<net>9 Million USD </net>
</competetor>
<competetor name = "competetor2">
<gross>xx Million</gross>
<net>xxx Million USD </net>
</competetor>
</Company-Financials>
</corporate-info>
</Body>
<Footers>
<Footer type = "pageCount">
Page X of Y
</Footer>
<Footer type = "copyright">copyright</Footer>
</Footers>
</Report>
The XML should contain as much information about the business as possible.
Your XML looks more HTML biassed.In the above XML , I have added one more
competetor2 to make things clear.
For the above XML , the XSL to produce your desired output will be..
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Report">
<body>
<h1 align="center">
<xsl:value-of select="Header"/>
</h1>
<table border="0" width="75%" align="center">
<tr>
<th bgcolor="red" align="left" colspan="2">
<xsl:value-of select="Body/Title"/>
</th>
<xsl:for-each
select="Body/corporate-info/Company-Financials/competetor">
<tr>
<th bgcolor="silver" align="left">
Company Financials
</th>
<th bgcolor="silver" align="left">
<xsl:value-of select="@name"/>
</th>
<xsl:for-each select="*">
<tr>
<th align="left">
<xsl:value-of select="name()"/>
</th>
<th align="left">
<xsl:value-of select="."/>
</th>
</tr>
</xsl:for-each>
</tr>
</xsl:for-each>
</tr>
</table>
<br/>
<br/>
<table border="0" width="75%" align="center">
<xsl:for-each select="Footers/Footer">
<tr>
<th align="center">
<xsl:value-of select="."/>
</th>
</tr>
</xsl:for-each>
</table>
<br/>
<hr/>
<br/>
</body>
</xsl:template>
</xsl:stylesheet>
This would print the HTML as you wanted.
If however you wanted to stick to your XML , Then
Do the following Changes
Changes to your XSL :
1. First Template Match "Report" instead of "/"
2. Change the line
<xsl:value-of select="//Header/Row/Column[(_at_)type]"/>
to <xsl:value-of select="Header/Row/Column[(_at_)type]"/>
( // would make the processor to search in the entire document )
3. Change the line <xsl:apply-templates select="//RowSet" /> to
<xsl:apply-templates select="Body/RowSet" />
( Your context node is Report. So match Body/Rowset. )
4. Change the line<xsl:apply-templates select="//Footer" />to
<xsl:apply-templates select="Footer" />
( You dont need a "//" here.)
5.Change
<br></br>
<hr></hr>
<br></br>
to <br/><hr/><br/>
( you dont need to do <br></br> u can have an empty element <br/>
6. line 43: Change <xsl:value-of
select="count(//RowSetHeader/Column)"></xsl:value-of> to
<xsl:value-of select="count(/RowSetHeader/Column)"></xsl:value-of>
7. line 47
Change <xsl:apply-templates select="child::*"/> to
<xsl:apply-templates select="RowSetBody"/>
You only need to match the child element called RowSetBody not the entire
child elements.
This is why the Title was getting printed again.
8. Line 50 Change
<xsl:template match="RowBody"> to
<xsl:template match="RowSetBody">
There is no RowBody Element in the XML file.
Changes 1,2,3,4,5 and 6 are to make your XSL efficient .
Changes 7,8 are to make your XSL work
Thaz it. It will work. I havent taken a deep look at the internals of how
you have dealt with getting the data onto HTML ..But these were the apparent
mistakes.
But as i had said before, Your XML doesnt show up data in a structured way.
This even causes an inefficient XSL. So If possible change your XML .
Gurus here may find more errors .I went as long as my patience took me ;)
Hope this helps.
Vasu
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list