XSLT Dynamic Rows - xslt

I'm having an issue with the data being properly formatted. The top level node is Part. The elements below the node are AML and Documents. The AML and Documents can be different values. AML can be greater than Documents and Documents can be greater then AML. I need the elements for Documents and AML to be on the same row, so that the table is properly formatted. Please let me know if you need anymore information and thank you for your help its greatly appreciated.
Data
<Item type="Part">
<item_number>E008643</item_number>
<Relationships>
<Item type="Part AML">
<related_id keyed_name="0000-009" type="Manufacturer Part">
<Item type="Manufacturer Part">
<manufacturer keyed_name="Fasteners Co." type="Manufacturer"></manufacturer>
<item_number>0000-009</item_number>
</Item>
</related_id>
<state>Preliminary</state>
</Item>
<Item type="Part AML">
<related_id keyed_name="1234" type="Manufacturer Part">
<Item type="Manufacturer Part">
<id keyed_name="1234" type="Manufacturer Part"></id>
<manufacturer keyed_name="Vishay/Dale" type="Manufacturer"></manufacturer>
<item_number>1234</item_number>
</Item>
</related_id>
<state>Preliminary</state>
</Item>
<Item type="Part Document">
<related_id keyed_name="D000006" type="Document">
<Item type="Document">
<id keyed_name="D000006" type="Document"></id>
<major_rev>B</major_rev>
<name>Hardware Doc</name>
<item_number>D000006</item_number>
</Item>
</related_id>
</Item>
<Item type="Part Document">
<related_id keyed_name="D000005" type="Document">
<Item type="Document">
<major_rev>B</major_rev>
<name>Firmware</name>
<item_number>D000005</item_number>
</Item>
</related_id>
</Item>
<Item type="Part Document">
<related_id keyed_name="D000003" type="Document">
<Item type="Document">
<major_rev>A</major_rev>
<name>Design Spec</name>
<item_number>D000003</item_number>
</Item>
</related_id>
</Item>
<Item type="Part BOM">
<related_id keyed_name="E000371" type="Part">
<Item type="Part">
<item_number>E000371</item_number>
<Relationships>
<Item type="Part AML">
<related_id keyed_name="3Z1JTTD" type="Manufacturer Part">
<Item type="Manufacturer Part">
<manufacturer keyed_name="Speer" type="Manufacturer"></manufacturer>
<item_number>3Z1JTTD</item_number>
</Item>
</related_id>
<state>Preliminary</state>
</Item>
<Item type="Part AML">
<related_id keyed_name="000T" type="Manufacturer Part">
<Item type="Manufacturer Part">
<manufacturer keyed_name="Nickel" type="Manufacturer"></manufacturer>
<item_number>000T</item_number>
</Item>
</related_id>
<source_id keyed_name="E000371" type="Part"></source_id>
<state>Preliminary</state>
</Item>
<Item type="Part AML">
<related_id keyed_name="R00V" type="Manufacturer Part">
<Item type="Manufacturer Part">
<manufacturer keyed_name="Sonic" type="Manufacturer"></manufacturer>
<item_number>R00V</item_number>
</Item>
</related_id>
<state>Preliminary</state>
</Item>
<Item type="Part AML">
<related_id keyed_name="TRF" type="Manufacturer Part">
<Item type="Manufacturer Part">
<manufacturer keyed_name="Components" type="Manufacturer"></manufacturer>
<item_number>TRF</item_number>
</Item>
</related_id>
<state>Preliminary</state>
</Item>
<Item type="Part AML">
<related_id keyed_name="70RL" type="Manufacturer Part">
<Item type="Manufacturer Part">
<manufacturer keyed_name="Comp" type="Manufacturer"></manufacturer>
<item_number>70RL</item_number>
</Item>
</related_id>
<state>Preliminary</state>
</Item>
<Item type="Part Document">
<related_id keyed_name="D000007" type="Document">
<Item type="Document">
<major_rev>B</major_rev>
<name>BOX</name>
<item_number>D000007</item_number>
</Item>
</related_id>
<state is_null="1" />
</Item>
<Item type="Part Document">
<related_id keyed_name="D000008" type="Document">
<Item type="Document">
<major_rev>A</major_rev>
<name>SOCKET</name>
<item_number>D000008</item_number>
</Item>
</related_id>
<state is_null="1" />
</Item>
</Relationships>
</Item>
</related_id>
</Item>
</Relationships>
Style Sheet
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:aras="http://www.aras-corp.com" exclude-result-prefixes="msxsl">
<xsl:output method="html" omit-xml-declaration="yes" standalone="yes" indent="yes"></xsl:output>
<xsl:template match="/">
<html>
<head></head>
<style type="text/css" userData="Global">
table {empty-cells:show; border-collapse:collapse;}
th {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid; background-color:#CCCCCC; text-transform:capitalize;}
td {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid;}
td.noBorder {font-family:helvetica; font-size:8pt; padding:2px; border-width:0;}
</style>
<body topmargin="50" leftmargin="50">
<table border="0" cellspacing="0" cellpadding="0" width="1850">
<tr valign="top">
<td class="noBorder" align="left" colspan="9" uniqueID="ms__id39">
</td>
</tr>
<tr valign="bottom">
<td class="noBorder" colspan="13" style="font-family:helvetica;font-size:15pt;color:#DA1943;padding:2px;" align="left" uniqueID="ms__id22">Bill of Materials Report - <xsl:value-of select="//Item/name"></xsl:value-of> Rev <xsl:value-of select="//Item/major_rev"></xsl:value-of>
</td>
<td class="noBorder" colspan="7" style="font-family:helvetica;font-size:10pt;padding:2px;" align="right" uniqueID="ms__id23">Generated on: <script>function m00(r, n){r += ""; if (!n) n = 2; while(r.length < n){r = "0" + r;} return r;} var dt = new Date(); var a = top.opener.top.aras; if (a){var s = m00(dt.getUTCFullYear(),4)+"-"+m00((dt.getUTCMonth()+1))+"-"+m00(dt.getUTCDate())+"T"+m00(dt.getUTCHours())+":"+m00(dt.getUTCMinutes())+":"+m00(dt.getUTCSeconds())+"+0000"; s = a.convertToNeutral(s, "date", "yyyy-MM-ddTHH:mm:sszzz"); s = a.convertFromNeutral(s, "date", "short_date"); document.write(s);}</script>
</td>
</tr>
<tr>
<th>Part Number</th>
<th>Manufacturer</th>
<th>Manufacturer Part</th>
<th>Document Number</th>
<th>Document Name</th>
<th>Document Rev</th>
</tr>
<xsl:apply-templates select="//Item[#type='Part']"></xsl:apply-templates>
</table>
</body>
<script src="../../javascript/PopupMenu.js"></script>
<script src="../../javascript/PopupMenu.js"></script>
<script src="../../javascript/PopupMenu.js"></script>
<script src="../../javascript/PopupMenu.js"></script>
</html>
</xsl:template>
<xsl:template match="Item[#type='Part']">
<!-- Find the number Row Span -->
<xsl:variable name="AML">
<xsl:choose>
<xsl:when test="count(Relationships/Item[#type='Part AML'])=0">1</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(Relationships/Item[#type='Part AML'])"></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Doc">
<xsl:choose>
<xsl:when test="count(Relationships/Item[#type='Part Document'])=0">1</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(Relationships/Item[#type='Part Document'])"></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="rowCount">
<xsl:choose>
<xsl:when test="$AML < $Doc"><xsl:value-of select="$Doc"></xsl:value-of></xsl:when>
<xsl:otherwise>
<xsl:value-of select="$AML"></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Grab values -->
<tr>
<td rowspan="{$rowCount}" width="5%" align="center" uniqueID="ms__id16">
<xsl:value-of select="item_number"></xsl:value-of>
</td>
<td width="13%" align="center" uniqueID="ms__id26">
<xsl:value-of select="Relationships/Item[#type='Part AML'][1]/related_id/Item/manufacturer/#keyed_name"></xsl:value-of>
</td>
<td width="13%" align="center" uniqueID="ms__id27">
<xsl:value-of select="Relationships/Item[#type='Part AML'][1]/related_id/Item/item_number"></xsl:value-of>
</td>
<td width="5%" align="center" uniqueID="ms__id28">
<xsl:value-of select="Relationships/Item[#type='Part Document'][1]/related_id/Item/item_number"></xsl:value-of>
</td>
<td width="13%px" align="center" uniqueID="ms__id29">
<xsl:value-of select="Relationships/Item[#type='Part Document'][1]/related_id/Item/name"></xsl:value-of>
</td>
<td width="8%" align="center" uniqueID="ms__id30">
<xsl:value-of select="Relationships/Item[#type='Part Document'][1]/related_id/Item/major_rev"></xsl:value-of>
</td>
<td rowspan="{$rowCount}" width="8%" align="center" uniqueID="ms__id37">
<xsl:value-of select="count(Relationships/Item[#type='Part AML'])"></xsl:value-of>
</td>
<td rowspan="{$rowCount}" width="8%" align="center" uniqueID="ms__id38">
<xsl:value-of select="count(Relationships/Item[#type='Part Document'])"></xsl:value-of>
</td>
<td rowspan="{$rowCount}" width="8%" align="center" uniqueID="ms__id40">
<xsl:value-of select="position() mod 2 = 1"></xsl:value-of>
</td>
</tr>
<!-- Assing first row for AML and Doc -->
<xsl:apply-templates select="Relationships/Item[#type='Part AML'][position()!=1]|Relationships/Item[#type='Part Document'][position()!=1]"></xsl:apply-templates>
</xsl:template>
<!-- AML and Doc Rows 2+ -->
<xsl:template match="text()" />
<xsl:template match="Item[#type = 'Part AML'][not(following-sibling::Item[1]/#type = 'Part Document')]">
<xsl:call-template name="ItemRow">
<xsl:with-param name="AmlItem" select="." />
</xsl:call-template>
</xsl:template>
<xsl:template match="Item[#type='Part Document']">
<xsl:variable name="lastItem" select="preceding-sibling::Item[1][#type = 'Part AML']" />
<xsl:call-template name="ItemRow">
<xsl:with-param name="AmlItem" select="$lastItem" />
<xsl:with-param name="PartDocument" select="." />
</xsl:call-template>
</xsl:template>
<xsl:template name="ItemRow">
<xsl:param name="AmlItem" />
<xsl:param name="PartDocument" select="_" />
<xsl:variable name="rowData">
<row value="{$AmlItem/related_id/Item/manufacturer/#keyed_name}" id="32" />
<row value="{$AmlItem/related_id/Item[#type='Manufacturer Part']/item_number}" id="33" />
<row value="{$PartDocument/related_id[#type='Document']/Item/item_number}" id="34" />
<row value="{$PartDocument/related_id[#type='Document']/Item/name}" id="35" />
<row value="{$PartDocument/related_id[#type='Document']/Item/major_rev}" id="36" />
</xsl:variable>
<tr>
<xsl:for-each select="msxsl:node-set($rowData)/row">
<td width="13%" align="center" uniqueID="ms__id{#id}">
<xsl:value-of select="#value"/>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
Output 1-7-12
<td width="13%" align="center" uniqueID="ms__id32">Bobs Workshop</td>
<td width="13%" align="center" uniqueID="ms__id33">1234</td>
<td width="13%" align="center" uniqueID="ms__id34">D000005</td>
<td width="13%" align="center" uniqueID="ms__id35">Firmware</td>
<td width="13%" align="center" uniqueID="ms__id36">B</td>
<td width="13%" align="center" uniqueID="ms__id34">D000003</td>
<td width="13%" align="center" uniqueID="ms__id35">Design Spec</td>
<td width="13%" align="center" uniqueID="ms__id36">A</td>
Desired Output
<!-- If both present -->
<tr>
<td width="13%" align="center" uniqueID="ms__id32">Bobs Workshop</td>
<td width="13%" align="center" uniqueID="ms__id33">1234</td>
<td width="13%" align="center" uniqueID="ms__id34">D000005</td>
<td width="13%" align="center" uniqueID="ms__id35">Firmware</td>
<td width="13%" align="center" uniqueID="ms__id36">B</td>
</tr>
<!-- If only Doc is present -->
<tr>
<td width="13%" align="center" uniqueID="ms__id32">""</td>
<td width="13%" align="center" uniqueID="ms__id33">""</td>
<td width="13%" align="center" uniqueID="ms__id34">D000003</td>
<td width="13%" align="center" uniqueID="ms__id35">Design Spec</td>
<td width="13%" align="center" uniqueID="ms__id36">A</td>
</tr>
<!-- If only AML is present -->
<tr>
<td width="13%" align="center" uniqueID="ms__id32">Nickel</td>
<td width="13%" align="center" uniqueID="ms__id33">000T</td>
<td width="13%" align="center" uniqueID="ms__id34">""</td>
<td width="13%" align="center" uniqueID="ms__id35">""</td>
<td width="13%" align="center" uniqueID="ms__id36">""</td>
</tr>
Desired Full HTML Output
<html xmlns:aras="http://www.aras-corp.com">
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-16">
</head>
<style type="text/css" userData="Global">
table {empty-cells:show; border-collapse:collapse;}
th {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid; background-color:#CCCCCC; text-transform:capitalize;}
td {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid;}
td.noBorder {font-family:helvetica; font-size:8pt; padding:2px; border-width:0;}
</style>
<body topmargin="50" leftmargin="50">
<table border="0" cellspacing="0" cellpadding="0" width="1850">
<tr valign="top">
</tr>
<tr valign="bottom">
<td class="noBorder" colspan="13" style="font-family:helvetica;font-size:15pt;color:#DA1943;padding:2px;" align="left" uniqueID="ms__id22">Bill of Materials Report - 9.6 Hz Parts Rev 1</td>
<td class="noBorder" colspan="7" style="font-family:helvetica;font-size:10pt;padding:2px;" align="right" uniqueID="ms__id23">Generated on: <script>function m00(r, n){r += ""; if (!n) n = 2; while(r.length < n){r = "0" + r;} return r;} var dt = new Date(); var a = top.opener.top.aras; if (a){var s = m00(dt.getUTCFullYear(),4)+"-"+m00((dt.getUTCMonth()+1))+"-"+m00(dt.getUTCDate())+"T"+m00(dt.getUTCHours())+":"+m00(dt.getUTCMinutes())+":"+m00(dt.getUTCSeconds())+"+0000"; s = a.convertToNeutral(s, "date", "yyyy-MM-ddTHH:mm:sszzz"); s = a.convertFromNeutral(s, "date", "short_date"); document.write(s);}</script></td>
</tr>
<tr>
<th colspan="6">Indenture Level</th>
<th>Part Number</th>
<th>Legacy Part Number</th>
<th>Revision</th>
<th>Name</th>
<th>Description</th>
<th>Parameters</th>
<th>RoHS/Pb-Free</th>
<th>Quantity</th>
<th>Reference Designator</th>
<th>Manufacturer</th>
<th>Manufacturer Part</th>
<th>Document Number</th>
<th>Document Name</th>
<th>Document Rev</th>
<th>Pos AML</th>
<th>Pos Doc</th>
<th>Mod</th>
</tr>
<tr>
<td rowspan="3" width="2%" align="center" uniqueID="ms__id10">0</td>
<td rowspan="3" width="2%" align="center" uniqueID="ms__id11"></td>
<td rowspan="3" width="2%" align="center" uniqueID="ms__id12"></td>
<td rowspan="3" width="2%" align="center" uniqueID="ms__id13"></td>
<td rowspan="3" width="2%" align="center" uniqueID="ms__id14"></td>
<td rowspan="3" width="2%" align="center" uniqueID="ms__id15"></td>
<td rowspan="3" width="5%" align="center" uniqueID="ms__id16">E008643</td>
<td rowspan="3" width="5%" align="center" uniqueID="ms__id17"></td>
<td rowspan="3" width="2%" align="center" uniqueID="ms__id18">1</td>
<td rowspan="3" width="13%" align="center" uniqueID="ms__id19">9.6 Hz Parts</td>
<td rowspan="3" width="13%" align="center" uniqueID="ms__id20">Test</td>
<td rowspan="3" width="13%" align="center" uniqueID="ms__id21">Assembly</td>
<td rowspan="3" width="5%" align="center" uniqueID="ms__id22"></td>
<td rowspan="3" width="5%" align="center" uniqueID="ms__id23">1</td>
<td rowspan="3" width="5%" align="center" uniqueID="ms__id24"></td>
<td width="13%" align="center" uniqueID="ms__id26">Fasteners Co.</td>
<td width="13%" align="center" uniqueID="ms__id27">009</td>
<td width="5%" align="center" uniqueID="ms__id28">D000006</td>
<td width="13%px" align="center" uniqueID="ms__id29">Hardware Doc</td>
<td width="8%" align="center" uniqueID="ms__id30">B</td>
<td rowspan="3" width="8%" align="center" uniqueID="ms__id37">2</td>
<td rowspan="3" width="8%" align="center" uniqueID="ms__id38">3</td>
<td rowspan="3" width="8%" align="center" uniqueID="ms__id40">true</td>
</tr>
<tr>
<td width="13%" align="center" uniqueID="ms__id32">Vishay/Dale</td>
<td width="13%" align="center" uniqueID="ms__id33">1234</td>
<td width="13%" align="center" uniqueID="ms__id34">D000005</td>
<td width="13%" align="center" uniqueID="ms__id35">Firmware</td>
<td width="13%" align="center" uniqueID="ms__id36">B</td>
</tr>
<tr>
<td width="13%" align="center" uniqueID="ms__id32"></td>
<td width="13%" align="center" uniqueID="ms__id33"></td>
<td width="13%" align="center" uniqueID="ms__id34">D000003</td>
<td width="13%" align="center" uniqueID="ms__id35">Design Spec</td>
<td width="13%" align="center" uniqueID="ms__id36">A</td>
</tr>
<tr>
<td rowspan="5" width="2%" align="center" uniqueID="ms__id10"></td>
<td rowspan="5" width="2%" align="center" uniqueID="ms__id11">1</td>
<td rowspan="5" width="2%" align="center" uniqueID="ms__id12"></td>
<td rowspan="5" width="2%" align="center" uniqueID="ms__id13"></td>
<td rowspan="5" width="2%" align="center" uniqueID="ms__id14"></td>
<td rowspan="5" width="2%" align="center" uniqueID="ms__id15"></td>
<td rowspan="5" width="5%" align="center" uniqueID="ms__id16">E000371</td>
<td rowspan="5" width="5%" align="center" uniqueID="ms__id17">0061</td>
<td rowspan="5" width="2%" align="center" uniqueID="ms__id18">A</td>
<td rowspan="5" width="13%" align="center" uniqueID="ms__id19">0?</td>
<td rowspan="5" width="13%" align="center" uniqueID="ms__id20">Thick Film ''</td>
<td rowspan="5" width="13%" align="center" uniqueID="ms__id21">0, 100, 0.05</td>
<td rowspan="5" width="5%" align="center" uniqueID="ms__id22">Yes</td>
<td rowspan="5" width="5%" align="center" uniqueID="ms__id23">1</td>
<td rowspan="5" width="5%" align="center" uniqueID="ms__id24">R34</td>
<td width="13%" align="center" uniqueID="ms__id26">Speer</td>
<td width="13%" align="center" uniqueID="ms__id27">RK73Z1JTTD</td>
<td width="5%" align="center" uniqueID="ms__id28">D000010</td>
<td width="13%px" align="center" uniqueID="ms__id29">BOX</td>
<td width="8%" align="center" uniqueID="ms__id30">B</td>
<td rowspan="5" width="8%" align="center" uniqueID="ms__id37">5</td>
<td rowspan="5" width="8%" align="center" uniqueID="ms__id38">3</td>
<td rowspan="5" width="8%" align="center" uniqueID="ms__id40">false</td>
</tr>
<tr>
<td width="13%" align="center" uniqueID="ms__id32">Nickel</td>
<td width="13%" align="center" uniqueID="ms__id33">000T</td>
<td width="13%" align="center" uniqueID="ms__id34">D000011</td>
<td width="13%" align="center" uniqueID="ms__id35">SOCKET</td>
<td width="13%" align="center" uniqueID="ms__id36">A</td>
</tr>
<tr>
<td width="13%" align="center" uniqueID="ms__id32">Sonic</td>
<td width="13%" align="center" uniqueID="ms__id33">R00V</td>
<td width="13%" align="center" uniqueID="ms__id34">D000007</td>
<td width="13%" align="center" uniqueID="ms__id35">MOUNT</td>
<td width="13%" align="center" uniqueID="ms__id36">A</td>
</tr>
<tr>
<td width="13%" align="center" uniqueID="ms__id32">NIC</td>
<td width="13%" align="center" uniqueID="ms__id33">OTRF</td>
<td width="13%" align="center" uniqueID="ms__id34"></td>
<td width="13%" align="center" uniqueID="ms__id35"></td>
<td width="13%" align="center" uniqueID="ms__id36"></td>
</tr>
<tr>
<td width="13%" align="center" uniqueID="ms__id32">Test</td>
<td width="13%" align="center" uniqueID="ms__id33">9874</td>
<td width="13%" align="center" uniqueID="ms__id34"></td>
<td width="13%" align="center" uniqueID="ms__id35"></td>
<td width="13%" align="center" uniqueID="ms__id36"></td>
</tr>
<tr>
<td rowspan="2" width="2%" align="center" uniqueID="ms__id10"></td>
<td rowspan="2" width="2%" align="center" uniqueID="ms__id11">1</td>
<td rowspan="2" width="2%" align="center" uniqueID="ms__id12"></td>
<td rowspan="2" width="2%" align="center" uniqueID="ms__id13"></td>
<td rowspan="2" width="2%" align="center" uniqueID="ms__id14"></td>
<td rowspan="2" width="2%" align="center" uniqueID="ms__id15"></td>
<td rowspan="2" width="5%" align="center" uniqueID="ms__id16">E001163</td>
<td rowspan="2" width="5%" align="center" uniqueID="ms__id17">0145</td>
<td rowspan="2" width="2%" align="center" uniqueID="ms__id18">A</td>
<td rowspan="2" width="13%" align="center" uniqueID="ms__id19">8200</td>
<td rowspan="2" width="13%" align="center" uniqueID="ms__id20">PPS Film ''</td>
<td rowspan="2" width="13%" align="center" uniqueID="ms__id21">
</td>
<td rowspan="2" width="5%" align="center" uniqueID="ms__id22">Yes</td>
<td rowspan="2" width="5%" align="center" uniqueID="ms__id23">30</td>
<td rowspan="2" width="5%" align="center" uniqueID="ms__id24">C1-C5,C12,C17,C22,C25,C27-C29,C31</td>
<td width="13%" align="center" uniqueID="ms__id26">Sonic</td>
<td width="13%" align="center" uniqueID="ms__id27">822GX5</td>
<td width="5%" align="center" uniqueID="ms__id28">D000012</td>
<td width="13%px" align="center" uniqueID="ms__id29">Doc Test</td>
<td width="8%" align="center" uniqueID="ms__id30">A</td>
<td rowspan="2" width="8%" align="center" uniqueID="ms__id37">2</td>
<td rowspan="2" width="8%" align="center" uniqueID="ms__id38">2</td>
<td rowspan="2" width="8%" align="center" uniqueID="ms__id40">true</td>
</tr>
<tr>
<td width="13%" align="center" uniqueID="ms__id32"></td>
<td width="13%" align="center" uniqueID="ms__id33"></td>
<td width="13%" align="center" uniqueID="ms__id34">D000008</td>
<td width="13%" align="center" uniqueID="ms__id35">ADAPTER</td>
<td width="13%" align="center" uniqueID="ms__id36">A</td>
</tr>
</table>
</body><script src="../../javascript/PopupMenu.js"></script><script src="../../javascript/PopupMenu.js"></script><script src="../../javascript/PopupMenu.js"></script><script src="../../javascript/PopupMenu.js"></script></html>

What XSLT processor are you using?
I believe this should do what you want:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:aras="http://www.aras-corp.com" exclude-result-prefixes="msxsl">
<xsl:output method="html" omit-xml-declaration="yes" standalone="yes" indent="yes"></xsl:output>
<xsl:template match="/">
<html>
<head></head>
<style type="text/css" userData="Global">
table {empty-cells:show; border-collapse:collapse;}
th {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid; background-color:#CCCCCC; text-transform:capitalize;}
td {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid;}
td.noBorder {font-family:helvetica; font-size:8pt; padding:2px; border-width:0;}
</style>
<body topmargin="50" leftmargin="50">
<table border="0" cellspacing="0" cellpadding="0" width="1850">
<tr valign="top">
<td class="noBorder" align="left" colspan="9" uniqueID="ms__id39">
</td>
</tr>
<tr valign="bottom">
<td class="noBorder" colspan="13" style="font-family:helvetica;font-size:15pt;color:#DA1943;padding:2px;" align="left" uniqueID="ms__id22">
Bill of Materials Report - <xsl:value-of select="//Item/name"></xsl:value-of> Rev <xsl:value-of select="//Item/major_rev"></xsl:value-of>
</td>
<td class="noBorder" colspan="7" style="font-family:helvetica;font-size:10pt;padding:2px;" align="right" uniqueID="ms__id23">
Generated on: <script>function m00(r, n){r += ""; if (!n) n = 2; while(r.length < n){r = "0" + r;} return r;} var dt = new Date(); var a = top.opener.top.aras; if (a){var s = m00(dt.getUTCFullYear(),4)+"-"+m00((dt.getUTCMonth()+1))+"-"+m00(dt.getUTCDate())+"T"+m00(dt.getUTCHours())+":"+m00(dt.getUTCMinutes())+":"+m00(dt.getUTCSeconds())+"+0000"; s = a.convertToNeutral(s, "date", "yyyy-MM-ddTHH:mm:sszzz"); s = a.convertFromNeutral(s, "date", "short_date"); document.write(s);}</script>
</td>
</tr>
<tr>
<th width="12%" colspan="6">Indent Level</th>
<th width="5%">Part Number</th>
<th width="13%">Manufacturer</th>
<th width="13%">Manufacturer Part</th>
<th width="13%">Document Number</th>
<th width="13%">Document Name</th>
<th width="13%">Document Rev</th>
<th width="8%">Pos AML</th>
<th width="8%">Pos Doc</th>
<th width="8%">Mod</th>
</tr>
<xsl:apply-templates select="//Item[#type='Part']"></xsl:apply-templates>
</table>
</body>
<script src="../../javascript/PopupMenu.js"></script>
<script src="../../javascript/PopupMenu.js"></script>
<script src="../../javascript/PopupMenu.js"></script>
<script src="../../javascript/PopupMenu.js"></script>
</html>
</xsl:template>
<xsl:template match="Item[#type='Part']">
<xsl:variable name="AmlItems" select="Relationships/Item[#type='Part AML']"/>
<xsl:variable name="DocItems" select="Relationships/Item[#type='Part Document']"/>
<xsl:variable name="MoreAmlItems" select="count($AmlItems) > count($DocItems)" />
<xsl:variable name="largerGroup" select="$AmlItems[$MoreAmlItems] | $DocItems[not($MoreAmlItems)]" />
<!-- Ensure rowCount is at least 1 -->
<xsl:variable name="rowCount" select="count($largerGroup) + (count($largerGroup) = 0)"/>
<!-- Grab values -->
<tr>
<xsl:call-template name="IndentLevel">
<xsl:with-param name="rowSpan" select="$rowCount" />
</xsl:call-template>
<td rowspan="{$rowCount}" align="center" uniqueID="ms__id16">
<xsl:value-of select="item_number"></xsl:value-of>
</td>
<xsl:apply-templates select="$largerGroup[1]" />
<td rowspan="{$rowCount}" align="center" uniqueID="ms__id37">
<xsl:value-of select="count($AmlItems)"></xsl:value-of>
</td>
<td rowspan="{$rowCount}" align="center" uniqueID="ms__id38">
<xsl:value-of select="count($DocItems)"></xsl:value-of>
</td>
<td rowspan="{$rowCount}" align="center" uniqueID="ms__id40">
<xsl:value-of select="position() mod 2 = 1"></xsl:value-of>
</td>
</tr>
<!-- Assing first row for AML and Doc -->
<xsl:apply-templates select="$largerGroup[position() > 1]"></xsl:apply-templates>
</xsl:template>
<xsl:template name="IndentLevel">
<xsl:param name="level" select="0" />
<xsl:param name="rowSpan" />
<td rowspan="{$rowSpan}" width="2%" align="center" uniqueID="ms__id{10+$level}">
<xsl:if test="count(ancestor::Item[#type = 'Part']) = $level">
<xsl:value-of select="$level"/>
</xsl:if>
</td>
<!-- Stop when we reach 5 -->
<xsl:if test="$level < 5">
<xsl:call-template name="IndentLevel">
<xsl:with-param name="level" select="$level + 1" />
<xsl:with-param name="rowSpan" select="$rowSpan" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- AML and Doc Rows 2+ -->
<xsl:template match="text()" />
<xsl:template match="Item[#type = 'Part AML']">
<xsl:variable name="pos" select="position()" />
<xsl:variable name="isTop" select="not(preceding-sibling::Item[#type = 'Part AML'])"/>
<xsl:call-template name="ItemRow">
<xsl:with-param name="AmlItem" select="." />
<xsl:with-param name="PartDocument" select="../Item[#type = 'Part Document'][position() = $pos + not($isTop)]" />
<xsl:with-param name="IsTop" select="$isTop" />
</xsl:call-template>
</xsl:template>
<xsl:template match="Item[#type='Part Document']">
<xsl:variable name="pos" select="position()" />
<xsl:variable name="isTop" select="not(preceding-sibling::Item[#type = 'Part Document'])"/>
<xsl:call-template name="ItemRow">
<xsl:with-param name="AmlItem" select="../Item[#type = 'Part AML'][position() = $pos + not($isTop)]" />
<xsl:with-param name="PartDocument" select="." />
<xsl:with-param name="IsTop" select="$isTop" />
</xsl:call-template>
</xsl:template>
<xsl:template name="ItemRow">
<xsl:param name="AmlItem" />
<xsl:param name="PartDocument" select="_" />
<xsl:param name="IsTop" />
<xsl:variable name="startingId" select="26 * $IsTop + 32 * not($IsTop)" />
<xsl:variable name="rowData">
<cell value="{$AmlItem/related_id/Item/manufacturer/#keyed_name}" />
<cell value="{$AmlItem/related_id/Item[#type='Manufacturer Part']/item_number}" />
<cell value="{$PartDocument/related_id[#type='Document']/Item/item_number}" />
<cell value="{$PartDocument/related_id[#type='Document']/Item/name}" />
<cell value="{$PartDocument/related_id[#type='Document']/Item/major_rev}" />
</xsl:variable>
<xsl:variable name="rowCells">
<xsl:call-template name="RowCells">
<xsl:with-param name="rowData" select="$rowData" />
<xsl:with-param name="startingId" select="$startingId" />
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$IsTop">
<xsl:copy-of select="$rowCells"/>
</xsl:when>
<xsl:otherwise>
<tr>
<xsl:copy-of select="$rowCells"/>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="RowCells">
<xsl:param name="rowData" />
<xsl:param name="startingId" />
<xsl:for-each select="msxsl:node-set($rowData)/cell">
<td align="center" uniqueID="ms__id{$startingId + position() - 1}">
<xsl:value-of select="#value"/>
</td>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
If you're using a non-Microsoft XSLT processor, you would need to change the msxsl namespace to something else according to the table on this page:
http://www.xml.com/pub/a/2003/07/16/nodeset.html
There seems to be an inconsistency between your source XML and your output. The <related_id> in the first Item has no type attribute, so your [#type='Manufacturer Part'] filter would fail to locate anything. Is there supposed to be a type attribute there?

In your first template I would change it like this.
<xsl:template match="Item[#type='Part AML']|Item[#type='Part Document']">
<tr>
<xsl:apply-templates select="related_id/Item/manufacturer/#keyed_name"/>
...
</tr>
</xsl:template>
That should build out your rows like you want.

Related

grouping elements and adding their element values in xslt

source document:
the below is the xml document.
<?xml version="1.0"?>
<Library>
<Book code="123">
<BookName>XML</BookName>
<Category>Programming</Category>
<Quantity>10</Quantity>
<Price>100</Price>
</Book>
<Book code="345">
<BookName>Photoshop</BookName>
<Category>Design</Category>
<Quantity>50</Quantity>
<Price>200</Price>
</Book>
<Book code="123">
<BookName>XML</BookName>
<Category>Programming</Category>
<Quantity>5</Quantity>
<Price>100</Price>
</Book>
<Book code="345">
<BookName>Photoshop</BookName>
<Category>Design</Category>
<Quantity>10</Quantity>
<Price>200</Price>
</Book>
<Book code="456">
<BookName>Illustrator</BookName>
<Category>Design</Category>
<Quantity>100</Quantity>
<Price>300</Price>
</Book>
</Library>
xslt stylesheet:
this is the present stylesheet. I have tried to use xslt 2. However, I am not getting how to get the desired output.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Books Information</h1>
<table border="1">
<xsl:for-each-group select="Library/Book" group-by="Category">
<xsl:sort select="current-grouping-key()"/>
<tr>
<td colspan="4">Category:
<b>
<xsl:value-of select="current-grouping-key()"/>
</b>
</td>
</tr>
<tr>
<th>Book Code</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Price</th>
</tr>
<xsl:apply-templates select="current-group()">
<xsl:sort select="#code"/>
</xsl:apply-templates>
</xsl:for-each-group>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Book">
<tr>
<td><xsl:value-of select="#code"/></td>
<td><xsl:value-of select="Quantity"/></td>
<td><xsl:value-of select="Price"/></td>
<td> </td>
</tr>
</xsl:template>
</xsl:stylesheet>
current output
<html>
<body>
<h1>Books Information</h1>
<table border="1">
<tr>
<td colspan="4">Category:
<b>Design</b></td>
</tr>
<tr>
<th>Book Code</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Price</th>
</tr>
<tr>
<td>345</td>
<td>50</td>
<td>200</td>
<td></td>
</tr>
<tr>
<td>345</td>
<td>10</td>
<td>200</td>
<td></td>
</tr>
<tr>
<td>456</td>
<td>100</td>
<td>300</td>
<td></td>
</tr>
<tr>
<td colspan="4">Category:
<b>Programming</b></td>
</tr>
<tr>
<th>Book Code</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Price</th>
</tr>
<tr>
<td>123</td>
<td>10</td>
<td>100</td>
<td></td>
</tr>
<tr>
<td>123</td>
<td>5</td>
<td>100</td>
<td></td>
</tr>
</table>
</body>
</html>
expected output
<html>
<body>
<h1>Books Information</h1>
<table border="1">
<tr>
<td colspan="4">Category:
<b>Design</b></td>
</tr>
<tr>
<th>Book Code</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Price</th>
</tr>
<tr>
<td>345</td>
<td>60</td>
<td>200</td>
<td>1200</td>
</tr>
<tr>
<td>456</td>
<td>100</td>
<td>300</td>
<td></td>
</tr>
<tr>
<td colspan="4">Subtotal: 1500</td>
</tr>
<tr>
<td colspan="4">Category:
<b>Programming</b></td>
</tr>
<tr>
<th>Book Code</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Price</th>
</tr>
<tr>
<td>123</td>
<td>15</td>
<td>1500</td>
<td></td>
</tr>
<tr>
<td colspan="4">subtotal: 1500</td>
</tr>
<tr>
<td colspan="4">Grand TOtal: 3000</td>
</tr>
</table>
</body>
</html>
It looks like you are doing two lots of grouping here. First by "Category" and within each category you then group by "Code".
You first grouping looks fine, but for the second grouping, you need to replace these lines...
<xsl:apply-templates select="current-group()">
<xsl:sort select="#code"/>
</xsl:apply-templates>
With these lines, as this will then group the books within the current category by their code
<xsl:for-each-group select="current-group()" group-by="#code">
<xsl:sort select="current-grouping-key()" />
<xsl:apply-templates select="." />
</xsl:for-each-group>
In terms of getting the totals for each group, you can use this expression
<xsl:value-of select="sum(current-group()/(Quantity * Price))" />
This will work for both groups, so can be used to get the amount for the "code" and the sub-total for the "category". For the overall total, it would just be this
<xsl:value-of select="sum(Library/Book/(Quantity * Price))" />
Try this XSLT
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Books Information</h1>
<table border="1">
<xsl:for-each-group select="Library/Book" group-by="Category">
<xsl:sort select="current-grouping-key()"/>
<tr>
<td colspan="4">Category:
<b>
<xsl:value-of select="current-grouping-key()"/>
</b>
</td>
</tr>
<tr>
<th>Book Code</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Price</th>
</tr>
<xsl:for-each-group select="current-group()" group-by="#code">
<xsl:sort select="current-grouping-key()" />
<xsl:apply-templates select="." />
</xsl:for-each-group>
<tr>
<td colspan="4">subtotal: <xsl:value-of select="sum(current-group()/(Quantity * Price))" /></td>
</tr>
</xsl:for-each-group>
<tr>
<td colspan="4">Total: <xsl:value-of select="sum(Library/Book/(Quantity * Price))" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Book">
<tr>
<td><xsl:value-of select="#code"/></td>
<td><xsl:value-of select="Quantity"/></td>
<td><xsl:value-of select="Price"/></td>
<td><xsl:value-of select="sum(current-group()/(Quantity * Price))" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>

duplication in xslt preceeding-sibling

i've the below xml document.
<toc-div>
<toc-item>
<toc-title>CHAPTER 1 INTRODUCTION</toc-title>
<toc-subitem num="1.">
<toc-title>The British Virgin Islands</toc-title>
<toc-pg>1.001</toc-pg>
</toc-subitem>
<toc-subitem num="2.">
<toc-title>History and early constitutional developments</toc-title>
<toc-pg>1.003</toc-pg>
</toc-subitem>
<toc-subitem num="3.">
<toc-title>Development as a financial centre</toc-title>
<toc-pg>1.008</toc-pg>
</toc-subitem>
<toc-subitem num="4.">
<toc-title>Common Law and Equity</toc-title>
<toc-pg>1.015</toc-pg>
</toc-subitem>
<toc-subitem num="5.">
<toc-title>Statutes</toc-title>
<toc-pg>1.017</toc-pg>
</toc-subitem>
<toc-subitem num="6.">
<toc-title>Taxation</toc-title>
<toc-pg>1.022</toc-pg>
</toc-subitem>
</toc-item>
and i'm applying the below xslt.
<xsl:template match="toc-subitem">
<table>
<td>
<xsl:value-of select="preceding-sibling::toc-title[1]"/>
</td></table>
<xsl:variable name="tocpg">
<xsl:value-of select="current()/toc-pg"/></xsl:variable>
<xsl:variable name="abc">
<xsl:choose>
<xsl:when test="not(contains(#num, '('))">
<xsl:value-of select="1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="before">
<xsl:value-of select="normalize-space(substring-before($tocpg, '.'))"/>
</xsl:variable>
<xsl:variable name="after">
<xsl:value-of select="normalize-space(substring-after($tocpg, '.'))"/>
</xsl:variable>
<xsl:variable name="z">
<xsl:value-of select="current()/#num"/>
</xsl:variable>
<xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')"/>
<xsl:variable name="numa" select="number(translate(#num, '.', ''))" />
<xsl:variable name="itemlevel">
<xsl:value-of select="$ThisDocument//ntw:nums[#num=$abc]/#word"/>
</xsl:variable>
<xsl:variable name="tocitemlevel">
<xsl:value-of select="concat('toc-item-', $itemlevel,'-level')"/>
</xsl:variable>
<xsl:variable name="conc">
<xsl:value-of select="concat('er:#BVI_CH_0',$before, '/P', normalize-space($tocpgtag))"/>
</xsl:variable>
<table class="{$tocitemlevel}">
<tbody>
<tr>
<td class="toc-subitem-num">
<xsl:value-of select="$z" />
</td>
<td class="toc-title">
<xsl:value-of select="current()/toc-title" />
</td>
<td class="toc-pg">
<a href="{$conc}">
<xsl:value-of select="current()/toc-pg" />
</a>
</td>
</tr>
</tbody>
</table>
</xsl:template>
when i'm applying this template, the output i'm getting is as below.
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">1.</td>
<td class="toc-title">The British Virgin Islands</td>
<td class="toc-pg">1.001</td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">2.</td>
<td class="toc-title">History and early constitutional developments</td>
<td class="toc-pg">1.003</td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">3.</td>
<td class="toc-title">Development as a financial centre</td>
<td class="toc-pg">1.008</td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">4.</td>
<td class="toc-title">Common Law and Equity</td>
<td class="toc-pg">1.015</td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">5.</td>
<td class="toc-title">Statutes</td>
<td class="toc-pg">1.017</td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">6.</td>
<td class="toc-title">Taxation</td>
<td class="toc-pg">1.022</td>
</tr>
</tbody>
</table>
but i want to get it as below
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">1.</td>
<td class="toc-title">The British Virgin Islands</td>
<td class="toc-pg">1.001</td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">2.</td>
<td class="toc-title">History and early constitutional developments</td>
<td class="toc-pg">1.003</td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">3.</td>
<td class="toc-title">Development as a financial centre</td>
<td class="toc-pg">1.008</td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">4.</td>
<td class="toc-title">Common Law and Equity</td>
<td class="toc-pg">1.015</td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">5.</td>
<td class="toc-title">Statutes</td>
<td class="toc-pg">1.017</td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">6.</td>
<td class="toc-title">Taxation</td>
<td class="toc-pg">1.022</td>
</tr>
</tbody>
</table>
please let me know where I'm going wrong.
Thanks
Note:
Your title table is not valid - it does not have <tr>.
The reason your XSLT gave you duplicate toc-title was that you printed it for every toc-subitem processed. In the solution below it is printed only once.
Make the following change to your XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="//toc-item">
<table>
<td>
<!-- Print the title *once* -->
<xsl:value-of select="./toc-title"/>
</td>
</table>
<!-- Process each subitem -->
<xsl:apply-templates select="toc-subitem"/>
</xsl:template>
<xsl:template match="toc-subitem">
<!-- Removed the <table> with the preceding sibling -->
<xsl:variable name="tocpg">
<xsl:value-of select="current()/toc-pg"/></xsl:variable>
<!-- Put the rest of your XSLT here, no changes there -->
</xsl:template>
</xsl:stylesheet>
You should use separate templates for this (I also cleaned up a bunch of the <xsl:variable>s):
<xsl:template match="toc-title">
<table>
<tr>
<td>
<xsl:value-of select="preceding-sibling::toc-title[1]"/>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="toc-subitem">
<xsl:variable name="tocpg" select="toc-pg" />
<xsl:variable name="abc" select="1 + contains(#num, '(')" />
<xsl:variable name="before"
select="normalize-space(substring-before($tocpg, '.'))"/>
<xsl:variable name="after"
select="normalize-space(substring-after($tocpg, '.'))"/>
<xsl:variable name="z" select="#num"/>
<xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')"/>
<xsl:variable name="numa" select="number(translate(#num, '.', ''))" />
<xsl:variable name="itemlevel"
select="$ThisDocument//ntw:nums[#num=$abc]/#word"/>
<xsl:variable name="tocitemlevel"
select="concat('toc-item-', $itemlevel,'-level')"/>
<xsl:variable name="conc"
select="concat('er:#BVI_CH_0',$before, '/P',
normalize-space($tocpgtag))"/>
<table class="{$tocitemlevel}">
<tbody>
<tr>
<td class="toc-subitem-num">
<xsl:value-of select="$z" />
</td>
<td class="toc-title">
<xsl:value-of select="toc-title" />
</td>
<td class="toc-pg">
<a href="{$conc}">
<xsl:value-of select="toc-pg" />
</a>
</td>
</tr>
</tbody>
</table>
</xsl:template>
However, I think putting every row in its own table is not a very good design. Why have you chosen to do that?
I don't really understand why you'd want output like that (<td> is not a valid child of <table>, for example, in HTML), but this stylesheet should get you closer (I rewrote the stylesheet to split your code into separate <xsl:template> elements):
Stylesheet
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<table>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="toc-item/toc-title">
<td><xsl:value-of select="."/></td>
</xsl:template>
<xsl:template match="toc-subitem">
<!--
I don't know how your code that fetches the TOC item level is supposed
to work so you'll have to figure that out yourself.
-->
<table class="toc-item-$level-level">
<tbody>
<tr>
<xsl:apply-templates select="#* | node()"/>
</tr>
</tbody>
</table>
</xsl:template>
<xsl:template match="#num">
<td class="toc-subitem-num">
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="toc-subitem/toc-title">
<td class="toc-title">
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="toc-pg">
<td class="toc-pg">
<a href="{concat('er:#BVI_CH_0', substring-before(., '.'), '/P', translate(., '.', '-'))}">
<xsl:value-of select="."/>
</a>
</td>
</xsl:template>
</xsl:stylesheet>
Input
<?xml version="1.0"?>
<toc-div>
<toc-item>
<toc-title>CHAPTER 1 INTRODUCTION</toc-title>
<toc-subitem num="1.">
<toc-title>The British Virgin Islands</toc-title>
<toc-pg>1.001</toc-pg>
</toc-subitem>
<toc-subitem num="2.">
<toc-title>History and early constitutional developments</toc-title>
<toc-pg>1.003</toc-pg>
</toc-subitem>
<toc-subitem num="3.">
<toc-title>Development as a financial centre</toc-title>
<toc-pg>1.008</toc-pg>
</toc-subitem>
<toc-subitem num="4.">
<toc-title>Common Law and Equity</toc-title>
<toc-pg>1.015</toc-pg>
</toc-subitem>
<toc-subitem num="5.">
<toc-title>Statutes</toc-title>
<toc-pg>1.017</toc-pg>
</toc-subitem>
<toc-subitem num="6.">
<toc-title>Taxation</toc-title>
<toc-pg>1.022</toc-pg>
</toc-subitem>
</toc-item>
</toc-div>
Output
<html>
<body>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
<table class="toc-item-$level-level">
<tbody>
<tr>
<td class="toc-subitem-num">1.</td>
<td class="toc-title">The British Virgin Islands</td>
<td class="toc-pg">
1.001
</td>
</tr>
</tbody>
</table>
<table class="toc-item-$level-level">
<tbody>
<tr>
<td class="toc-subitem-num">2.</td>
<td class="toc-title">History and early constitutional developments</td>
<td class="toc-pg">
1.003
</td>
</tr>
</tbody>
</table>
<table class="toc-item-$level-level">
<tbody>
<tr>
<td class="toc-subitem-num">3.</td>
<td class="toc-title">Development as a financial centre</td>
<td class="toc-pg">
1.008
</td>
</tr>
</tbody>
</table>
<table class="toc-item-$level-level">
<tbody>
<tr>
<td class="toc-subitem-num">4.</td>
<td class="toc-title">Common Law and Equity</td>
<td class="toc-pg">
1.015
</td>
</tr>
</tbody>
</table>
<table class="toc-item-$level-level">
<tbody>
<tr>
<td class="toc-subitem-num">5.</td>
<td class="toc-title">Statutes</td>
<td class="toc-pg">
1.017
</td>
</tr>
</tbody>
</table>
<table class="toc-item-$level-level">
<tbody>
<tr>
<td class="toc-subitem-num">6.</td>
<td class="toc-title">Taxation</td>
<td class="toc-pg">
1.022
</td>
</tr>
</tbody>
</table>
</table>
</body>
</html>
Just remove the <html> and <body> elements from the first <xsl:template> rule if you really don't need them.

XSLT Remove Blank Element

I'm trying to remove empty elements within my XML document. I want id31, id32 and id33 removed when they are empty. Below is an example of the XSLT output. I'm trying to use the XSLT below but I'm not having any luck. Any ideas on what I'm doing wrong? Thanks
Data
<Item type="Part AML">
<related_id>
<Item type="Manufacturer Part">
<id keyed_name="1234" type="Manufacturer Part"></id>
<manufacturer keyed_name="Bobs Workshop" type="Manufacturer"></manufacturer>
<item_number>1234</item_number>
</Item>
</related_id>
</Item>
<Item type="Part Document">
<related_id keyed_name="D000005" type="Document">
<Item type="Document">
<id keyed_name="D000005" type="Document"></id>
<major_rev>B</major_rev>
<name>Firmware 8-16-12</name>
<item_number>D000005</item_number>
</Item>
</related_id>
</Item>
<Item type="Part Document">
<related_id keyed_name="D000003" type="Document">
<Item type="Document">
<id keyed_name="D000003" type="Document"></id>
<major_rev>A</major_rev>
<name>Design Spec</name>
<item_number>D000003</item_number>
</Item>
</related_id>
</Item>
Output
<td width="5%" align="center" uniqueID="ms__id31"></td>
<td width="13%" align="center" uniqueID="ms__id32"></td>
<td width="13%" align="center" uniqueID="ms__id33"></td>
<td width="5%" align="center" uniqueID="ms__id34">D000003</td>
<td width="13%" align="center" uniqueID="ms__id35">Design Spec</td>
<td width="8%" align="center" uniqueID="ms__id36">A</td>
Code from forums
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(#*|*|comment()|processing-instruction()) and normalize-space()='']"/>
My XSLT
<xsl:template match="Item[#type='Part AML']|Item[#type='Part Document']">
<tr>
<td width="5%" align="center" uniqueID="ms__id31">
<xsl:value-of select="state"/>
</td>
<td width="13%" align="center" uniqueID="ms__id32">
<xsl:value-of select="related_id[#type='Manufacturer Part']/Item/manufacturer/#keyed_name"/>
</td>
<td width="13%" align="center" uniqueID="ms__id33">
<xsl:value-of select="related_id[#type='Manufacturer Part']/Item/item_number"></xsl:value-of>
</td>
<td width="13%" align="center" uniqueID="ms__id34">
<xsl:value-of select="related_id[#type='Document']/Item/item_number"></xsl:value-of>
</td>
<td width="13%" align="center" uniqueID="ms__id35">
<xsl:value-of select="related_id[#type='Document']/Item/name"/>
</td>
<td width="8%" align="center" uniqueID="ms__id36">
<xsl:value-of select="related_id[#type='Document']/Item/major_rev"/>
</td>
</tr>
Use templates. This way, none are applied in the empty case:
<xsl:template match="Item[#type='Part AML']|Item[#type='Part Document']">
<tr>
<xsl:apply-templates select="state"/>
<xsl:apply-templates select="related_id[#type='Manufacturer Part']/Item/manufacturer/#keyed_name"/>
<xsl:apply-templates select="related_id[#type='Manufacturer Part']/Item/item_number">
<td width="13%" align="center" uniqueID="ms__id34">
<xsl:value-of select="related_id[#type='Document']/Item/item_number"></xsl:value-of>
</td>
<td width="13%" align="center" uniqueID="ms__id35">
<xsl:value-of select="related_id[#type='Document']/Item/name"/>
</td>
<td width="8%" align="center" uniqueID="ms__id36">
<xsl:value-of select="related_id[#type='Document']/Item/major_rev"/>
</td>
</tr>
</xsl:template>
<xsl:template match="Item[#type='Part AML' or #type='Part Document']/state">
<td width="5%" align="center" uniqueID="ms__id31">
<xsl:apply-templates>
</td>
</xsl:template>
<xsl:template match="Item[#type='Part AML' or #type='Part Document']/related_id[#type='Manufacturer Part']/Item/manufacturer/#keyed_name">
<td width="13%" align="center" uniqueID="ms__id32">
<xsl:apply-templates>
</td>
</xsl:template>
<xsl:template match="Item[#type='Part AML' or #type='Part Document']/related_id[#type='Manufacturer Part']/Item/item_number">
<td width="13%" align="center" uniqueID="ms__id33">
<xsl:apply-templates>
</td>
</xsl:template>
You can use the same pattern for the remaining <td>s if they might have empty values too.

selecting drop-down value in xsl

How to select the drop down value ? Am trying to display some data whenever I select some value in a drop-down in xsl. For example, If A is selected in the drop-down, details pertaining to A will be displayed in a table. Similarly, if B is selcted, only details relevant to B will be displayed. I need to write a line of code in xslt to select the drop down value in an if statement.
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>VPGate Media Mixer</title>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
<meta http-equiv="refresh" content="15"></meta>
<script src="/Common/common.js\" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style001.css" />
<link rel="stylesheet" type="text/css" href="Grid.Default.css" />
</head>
<body class="WorkArea">
<div class="divSummaryHeader" id="SummaryHeader">
<h1>Media Mixer - VPGate</h1>
</div>
 
<div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:828px;height:510px;overflow:auto">
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>
</tr>
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Summary</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
</tr>
<xsl:if test="MediaMixer!= ''">
<xsl:for-each select="MediaMixer/Conference">
<!--<xsl:sort select="Name"/>-->
<xsl:if test="Name !=''">
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td>
<tr class="rgRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:if>
<xsl:if test="MediaMixer = ''">
<td valign = "top">
<xsl:text>No Data </xsl:text>
</td>
</xsl:if>
</table>
</td>
</tr>
</table>
 
<div align="center">
<b> Please select a Conference Name :</b>
 
<select name="combo" id="combo">
<xsl:for-each select="MediaMixer/Conference">
<option>
<xsl:value-of select="Name"/>
</option>
</xsl:for-each>
</select>
</div>
<script type="text/C#" runat="server">
</script>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1">
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Details</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant ID 1</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant ID 2</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
</tr>
<xsl:if test="MediaMixer!= ''">
<xsl:for-each select="MediaMixer/Conference">
<xsl:if test="Name='combo.SelectedValue'">
<xsl:for-each select="Participant">
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="../Name"/>
</td>
<td valign = "top">
<xsl:value-of select="../ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="translate(ID1,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td>
<tr class="rgRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="../Name"/>
</td>
<td valign = "top">
<xsl:value-of select="../ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="translate(ID1,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:if>
<xsl:if test="MediaMixer= ''">
<td valign = "top">
<xsl:text>No Data </xsl:text>
</td>
</xsl:if>
</table>
</td>
</tr>
</table>
 
<div style="display:none">
<iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
If you are building a HTML page out of XML data with client side XSLT in the Browser, be aware that XSLT can only define the transformation process. When the HTML is ready, XSLT has finished its job. What you can do is to insert javascript into the XSLT source, that reacts on drop-down changes and hides the inappropiate data. The XSLT can't communicate with the Javascript, because the Javascript will begin to work after the page is complete and XSLT is already finished. But it can fit the javascript into the HTML source. Just imagine how to work this out in plain HTML without XSLT and let XSLT build this HTML.

Adding alternate colors to a table

I have an asp.net web application. The application reads data from an xml. The xml has a reference to a xslt file which takes care of the table design and alignment. I add data to the xml in a dynamic manner.
I want every alternate row of the table to have a color (say grey) for readability. I believe it can be done in xslt itself using the line of code
<xsl:if test="(position() mod 2 = 0)">
Can someone please tell me how to do it? I have posted my xslt fully below.
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>VPGate Media Mixer</title>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
<meta http-equiv="refresh" content="15"></meta>
<script src="/Common/common.js\" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style001.css" />
<link rel="stylesheet" type="text/css" href="Grid.Default.css" />
</head>
<body class="WorkArea">
<div class="divSummaryHeader" id="SummaryHeader">
<h1>Media Mixer - VPGate</h1>
<xsl:for-each select="MMDiagnostics/Conference">
<h1>
Media Mixer - <xsl:value-of select="name"/>
</h1>
</xsl:for-each>
</div>
 
<div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:630px;overflow:auto">
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>
</tr>
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Id</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
</tr>
<xsl:for-each select="MediaMixer/Conference">
<!--<xsl:sort select="Name"/>-->
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td bgcolor="#aaaaff">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:for-each>
</table>
</td>
</tr>
</table>
 
<table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Participant</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 1</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 2</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
</tr>
<xsl:for-each select="MediaMixer/Conference/Participant">
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="ID1"/>
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td bgcolor="#aaaaff">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="ID1"/>
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:for-each>
</table>
</td>
</tr>
</table>
 
<div style="display:none">
<iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
You're actually on the right track. Assign numbered css classes and use position() mod 2 to compute which css class to call.
Here's a demonstration:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output version="1.0" encoding="utf-8" indent="yes" method="html"/>
<xsl:template match="/">
<xsl:variable name="sortValue">title</xsl:variable>
<style type="text/css">
.row0 { background-color: blue; }
.row1 { background-color: red; }
</style>
<table border='1'>
<tr>
<th>ID</th>
<th>Artist</th>
<th>Title</th>
<th>Album</th>
<th>Length</th>
</tr>
<xsl:for-each select="*/song">
<xsl:variable name="rowClass">
row <xsl:number value="position() mod 2"/>
</xsl:variable>
<tr>
<td class="{$rowClass}"><xsl:value-of select="./#id"/></td>
<td class="{$rowClass}"><xsl:value-of select="./artist"/></td>
<td class="{$rowClass}"><xsl:value-of select="./title"/></td>
<td class="{$rowClass}"><xsl:value-of select="./album"/></td>
<td class="{$rowClass}"><xsl:value-of select="./length"/></td>
</tr>
</xsl:for-each>
</table>
HTH.