I am new to XSLT and am experimenting to write a small application. What
the application does is to transform XML into a table based on platform
column type. Even through XML each product and platform entries are in a
separate row in XML, I want to flatten and display all platforms for a
product on the same row of the table in rendered HTML. My data looks
like as follows:
<?xml version="1.0"?>
<!DOCTYPE deliv SYSTEM
"http://santhi.us.oracle.com:7777/stylesheets/deliv.dtd">
<?xml-stylesheet type="text/xsl"
href="http://santhi.us.oracle.com:7777/stylesheets/delivshow.xsl"?>
<deliv>
<delivtable>
<platforms>
<platrow DelivPlatID="60" Vendor="IBM" PlatformName="AIX"
Release="4.3.2" />
<platrow DelivPlatID="61" Vendor="IBM" PlatformName="AIX"
Release="4.3.3" />
<platrow DelivPlatID="62" Vendor="IBM" PlatformName="AIX" Release="5L" />
<platrow DelivPlatID="1" Vendor="HP" PlatformName="HP-UX"
Release="10.20" />
<platrow DelivPlatID="2" Vendor="HP" PlatformName="HP-UX"
Release="11.0" />
<platrow DelivPlatID="3" Vendor="HP" PlatformName="HP-UX" Release="11i" />
<platrow DelivPlatID="90" Vendor="RedHat" PlatformName="Linux"
Release="6.0" />
<platrow DelivPlatID="94" Vendor="RedHat" PlatformName="Linux"
Release="AS2.1" />
<platrow DelivPlatID="95" Vendor="RedHat" PlatformName="Linux"
Release="ES7" />
<platrow DelivPlatID="93" Vendor="RedHat" PlatformName="Linux"
Release="7.3" />
<platrow DelivPlatID="91" Vendor="RedHat" PlatformName="Linux"
Release="6.2" />
<platrow DelivPlatID="92" Vendor="RedHat" PlatformName="Linux"
Release="7.2" />
<platrow DelivPlatID="30" Vendor="HP" PlatformName="Tru64"
Release="4.0d" />
<platrow DelivPlatID="31" Vendor="HP" PlatformName="Tru64"
Release="5.0a" />
<platrow DelivPlatID="32" Vendor="HP" PlatformName="Tru64"
Release="5.0b" />
</platforms>
<deliverables>
<delivrow Did="0" ProductId="2" Release="6.0 " PlatID="94"
CompletionDate="01/01/1994" TargetDate="02/01/1994" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="10" Release="5.0 " PlatID="95"
CompletionDate="01/03/1995" TargetDate="02/01/1995" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="46" Release="5.0 " PlatID="62"
CompletionDate="01/01/1962" TargetDate="02/01/1962" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="123" Release="Env " PlatID="30"
CompletionDate="01/01/2030" TargetDate="02/01/2030" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="123" Release="FAQ " PlatID="32"
CompletionDate="01/01/2032" TargetDate="02/01/2032" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="193" Release="5.0 " PlatID="1"
CompletionDate="01/01/2001" TargetDate="02/01/2001" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="193" Release="5.1 " PlatID="30"
CompletionDate="01/02/2030" TargetDate="02/01/2030" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="193" Release="4.3 " PlatID="60"
CompletionDate="01/01/1960" TargetDate="02/01/1960" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="193" Release="5.1 " PlatID="90"
CompletionDate="01/01/1990" TargetDate="02/01/1990" TypeOfRelease="FR"
BaseRelease="4.3.2" />
<delivrow Did="0" ProductId="276" Release="5.0 " PlatID="60"
CompletionDate="01/01/1960" TargetDate="02/01/1960" TypeOfRelease="FR"
BaseRelease="4.3.2" />
</deliverables>
</delivtable>
</deliv>
and my stylesheet looks as follows:
............................
............................
<xsl:key name="prodlookup" match="delivrow" use="@ProductId"/>
...........................
..........................
<table>
<xsl:variable name="uniqueIds"
select="//deliv/delivtable/deliverables/delivrow[not(@ProductId=preceding::delivrow/@ProductId)]"
/>
<xsl:for-each select="$uniqueIds">
<xsl:variable name="currentrow" select="."/>
<xsl:variable name="tmpprodvector" select="key('prodlookup',
$currentrow/@ProductId)"/>
<tr>
<td><xsl:value-of select="$currentrow/@ProductId"/></td>
<xsl:for-each select="/deliv/delivtable/platforms/platrow" >
<xsl:sort select="@*[name()=$plat_sortfield]"
order="{$sortorder}" data-type="{$plat_sortfieldtype}" />
<xsl:variable name="currentplatrow" select="."/>
<xsl:for-each select="$tmpprodvector">
<xsl:if test="@PlatID != $currentplatrow/@DelivPlatID">
<td>N/A</td>
</xsl:if>
<xsl:if test="@PlatID = $currentplatrow/@DelivPlatID">
<td><xsl:value-of select="@TargetDate"/></td>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
The above stylesheet shows 30 <td> elements for product with id 123
whereas i want to show 15 elements with only two relevant dates filled
properly. Is there an easier way to do this? Am i missing something here?
Appreciate any inputs on this.
Ramesh
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list