Recursive Template Generating Extra Stuff - xslt

I am working with Xml that that has multiple levels where I am attempting to display as nested html tables. The Xml may contain one or more levels of information. The current state is the information from the Xml is shown, but has extra empty tables.
Below is the Xml and template I am using. How should I correct the problem?
<?xml version="1.0" encoding="UTF-8"?>
<ErrorRecord>
<Exception>
<ErrorRecord>Exception calling "Fill" with "2" argument(s): "Divide by zero error encountered."</ErrorRecord>
<WasThrownFromThrowStatement>True</WasThrownFromThrowStatement>
<TargetSite>Void CheckActionPreference(System.Management.Automation.Language.FunctionContext, System.Exception)</TargetSite>
<Message>Exception calling "Fill" with "2" argument(s): "Divide by zero error encountered."</Message>
<Data>System.Collections.ListDictionaryInternal</Data>
<InnerException>
<Error>
<Source>Core .Net SqlClient Data Provider</Source>
<Number>8134</Number>
<State>1</State>
<Class>16</Class>
<Server>.</Server>
<Message>Divide by zero error encountered.</Message>
<Procedure></Procedure>
<LineNumber>1</LineNumber>
</Error>
<ClientConnectionId>cdfed373-14fb-4dd7-bebf-7158695cb2c7</ClientConnectionId>
<Class>16</Class>
<LineNumber>1</LineNumber>
<Number>8134</Number>
<Procedure></Procedure>
<Server>.</Server>
<State>1</State>
<Source>Core .Net SqlClient Data Provider</Source>
<IsTransient>False</IsTransient>
<SqlState></SqlState>
<BatchCommand></BatchCommand>
<ErrorCode>-2146232060</ErrorCode>
<TargetSite>Void OnError(System.Data.SqlClient.SqlException, Boolean, System.Action`1[System.Action])</TargetSite>
<Message>Divide by zero error encountered.</Message>
<Data>System.Collections.ListDictionaryInternal</Data>
<InnerException></InnerException>
<HelpLink></HelpLink>
<HResult>-2146232060</HResult>
<StackTrace> at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at CallSite.Target(Closure, CallSite, Object, Object, Object)</StackTrace>
</InnerException>
<HelpLink></HelpLink>
<Source>System.Management.Automation</Source>
<HResult>-2146233087</HResult>
<StackTrace> at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)</StackTrace>
</Exception>
</ErrorRecord>
<xsl:template match = "ErrorRecord">
<xsl:call-template name="ErrorTable">
<xsl:with-param name="n" select="." />
</xsl:call-template>
</xsl:template>
<xsl:template name="ErrorTable">
<xsl:param name="n" />
<xsl:for-each select="$n/*">
<table class="ErrorDetailTable">
<tr>
<th class="Property"> </th>
<th class="Value"> </th>
</tr>
<xsl:for-each select="*">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<tr class="tr-even">
<xsl:call-template name="ErrorCells"/>
</tr>
</xsl:when>
<xsl:otherwise>
<tr class="tr-odd">
<xsl:call-template name="ErrorCells"/>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<tr><td colspan="2"> </td></tr>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template name="ErrorCells">
<td class="Property"><xsl:value-of select ="local-name(.)"/></td>
<td class="Value">
<xsl:choose>
<xsl:when test="count(./*) > 0">
<xsl:call-template name="ErrorTable">
<xsl:with-param name="n" select=".." />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="replace_sab">
<xsl:with-param name="s" select="." />
<xsl:with-param name="a" select="'
'" />
<xsl:with-param name="b"><br /></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:template>
<xsl:template name="replace_sab">
<!-- with string s, replace substring a by string b -->
<!-- s, a and b are parameters determined upon calling -->
<xsl:param name="s" />
<xsl:param name="a" />
<xsl:param name="b" />
<xsl:choose>
<xsl:when test="contains($s,$a)">
<xsl:value-of select="substring-before($s,$a)" />
<xsl:copy-of select="$b" />
<xsl:call-template name="replace_sab">
<xsl:with-param name="s" select="substring-after($s,$a)" />
<xsl:with-param name="a" select="$a" />
<xsl:with-param name="b" select="$b" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$s" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

I was able to find the issue, which was due to the reference to the current node with the xml. Solution is as below.
<xsl:template match = "ErrorRecord">
<xsl:call-template name="ErrorTable">
<xsl:with-param name="n" select="./Exception" />
</xsl:call-template>
</xsl:template>
<xsl:template name="ErrorTable">
<xsl:param name="n" />
<xsl:for-each select="$n">
<table class="ErrorDetailTable">
<tr>
<th class="Property"> </th>
<th class="Value"> </th>
</tr>
<xsl:for-each select="*">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<tr class="tr-even">
<xsl:call-template name="ErrorCells"/>
</tr>
</xsl:when>
<xsl:otherwise>
<tr class="tr-odd">
<xsl:call-template name="ErrorCells"/>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<tr><td colspan="2"> </td></tr>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template name="ErrorCells">
<td class="Property"><xsl:value-of select ="local-name(.)"/></td>
<td class="Value">
<xsl:choose>
<xsl:when test="count(./*) > 0">
<xsl:call-template name="ErrorTable">
<xsl:with-param name="n" select="." />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="replace_sab">
<xsl:with-param name="s" select="." />
<xsl:with-param name="a" select="'
'" />
<xsl:with-param name="b"><br /></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:template>
<xsl:template name="replace_sab">
<!-- with string s, replace substring a by string b -->
<!-- s, a and b are parameters determined upon calling -->
<xsl:param name="s" />
<xsl:param name="a" />
<xsl:param name="b" />
<xsl:choose>
<xsl:when test="contains($s,$a)">
<xsl:value-of select="substring-before($s,$a)" />
<xsl:copy-of select="$b" />
<xsl:call-template name="replace_sab">
<xsl:with-param name="s" select="substring-after($s,$a)" />
<xsl:with-param name="a" select="$a" />
<xsl:with-param name="b" select="$b" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$s" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Related

Switching Math to %Reported from just a count of Present

Screenshot of tool
I have the following code that was written by another developer. I have taken it as far as I can since I am not versed in XSLT.
Currently the math is set to just do a percentage of just those that have marked themselves P (Present). I want the percentage to count everything but NR (not reported), or just do a math equation where it counts the NR percentage and subtracts it from 100% - either way will work.
Woolf CTR Sonia E
4:47 PM (21 minutes ago)
to me
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">&apos;</xsl:param>
<xsl:param name="dvt_groupfield" />
<xsl:param name="ListName">Morning Report</xsl:param>
<xsl:param name="Day" />
<xsl:param name="Monday">=(2-WEEKDAY(Today)+(Today))</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<xsl:variable name="dvt_RowCount" select="count($Rows)" />
<xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<th class="ms-vh" width="1%" nowrap="nowrap"></th>
</xsl:if>
<th class="ms-vh" nowrap="" style="width: 129px">Name</th>
<xsl:call-template name="table_header_query">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template></tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
<xsl:with-param name="FirstRow" select="1" />
<xsl:with-param name="LastRow" select="$dvt_RowCount" />
</xsl:call-template>
<xsl:call-template name="dvt_1.footer">
<xsl:with-param name="Rows" select="$Rows" />
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<xsl:variable name="dvt_Rows"><root>
<xsl:for-each select="$Rows">
<xsl:if test="(position() >= $FirstRow and position() <= $LastRow)"><xsl:copy-of select="." /></xsl:if>
</xsl:for-each>
</root></xsl:variable>
<xsl:for-each select="$Rows">
<xsl:variable name="NewGroup_0">
<xsl:choose>
<xsl:when test="not ($dvt_groupfield)"><xsl:value-of select="ddwrt:NameChanged(string(#PdM), 0)" /></xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="0" />
<xsl:when test="not($dvt_groupfield) and (not($NewGroup_0='') and position() >= $FirstRow and position() <= $LastRow or ($FirstRow = position()))">
<xsl:variable name="groupheader0">
<xsl:choose>
<xsl:when test="not (#PdM) and (#PdM) != false()"><xsl:value-of select="' '" /></xsl:when>
<xsl:otherwise><xsl:value-of select="#PdM" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="groupfooter0">
<xsl:choose>
<xsl:when test="$NewGroup_0=''"><xsl:value-of select="#PdM" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$NewGroup_0" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="not ((position()=1) or (position()=$FirstRow))">
<xsl:call-template name="dvt_1.groupfooter0">
<xsl:with-param name="fieldtitle">Org</xsl:with-param>
<xsl:with-param name="fieldname">PdM</xsl:with-param>
<xsl:with-param name="fieldvalue" select="$groupfooter0" />
<xsl:with-param name="fieldtype" select="''" />
<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((#PdM)=$groupfooter0 or ((not(#PdM) or #PdM='') and $groupfooter0=' '))]" />
<xsl:with-param name="groupid" select="'0'" />
<xsl:with-param name="displaystyle" select="'auto'" />
<xsl:with-param name="showfooter" select="true()" />
<xsl:with-param name="showfootercolumn" select="false()" />
</xsl:call-template>
</xsl:if>
<xsl:call-template name="dvt_1.groupheader0">
<xsl:with-param name="fieldtitle">Org</xsl:with-param>
<xsl:with-param name="fieldname">PdM</xsl:with-param>
<xsl:with-param name="fieldvalue" select="$groupheader0" />
<xsl:with-param name="fieldtype" select="''" />
<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((#PdM)=$groupheader0 or ((not(#PdM) or #PdM='') and $groupheader0=' '))]" />
<xsl:with-param name="groupid" select="'0'" />
<xsl:with-param name="displaystyle" select="'auto'" />
<xsl:with-param name="imagesrc" select="'/_layouts/images/plus.gif'" />
<xsl:with-param name="alttext" select="'expand'" />
<xsl:with-param name="altname" select="'collapse'" />
<xsl:with-param name="hidedetail" select="false()" />
<xsl:with-param name="showheader" select="true()" />
<xsl:with-param name="showheadercolumn" select="false()" />
</xsl:call-template>
</xsl:when>
</xsl:choose>
<xsl:variable name="BreakOut">
<xsl:choose>
<xsl:when test="not($dvt_groupfield) and position()=$LastRow+1"><xsl:value-of select="ddwrt:NameChanged('', -1)" /></xsl:when>
<xsl:otherwise>BreakOut</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="dvt_KeepItemsTogether" select="false()" />
<xsl:variable name="dvt_HideGroupDetail" select="false()" />
<xsl:if test="(position() >= $FirstRow and position() <= $LastRow) or $dvt_KeepItemsTogether">
<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
<xsl:call-template name="dvt_1.rowview" />
</xsl:if>
</xsl:if>
<xsl:choose>
<xsl:when test="0" />
<xsl:when test="($NewGroup_0 or true()) and not($dvt_groupfield)">
<xsl:variable name="groupfooter0">
<xsl:choose>
<xsl:when test="position() = count($Rows) and ($LastRow >= position() or $dvt_KeepItemsTogether) or not($NewGroup_0) or $NewGroup_0=''"><xsl:value-of select="#PdM" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$NewGroup_0" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="(position() = count($Rows) and ($LastRow=position() or $dvt_KeepItemsTogether)) or (not($dvt_KeepItemsTogether) and position() > $LastRow and not($BreakOut='BreakOut')) or (not($dvt_KeepItemsTogether) and position() = $LastRow+1) or (position()=last() and $LastRow > last())">
<xsl:call-template name="dvt_1.groupfooter0">
<xsl:with-param name="fieldtitle">Org</xsl:with-param>
<xsl:with-param name="fieldname">PdM</xsl:with-param>
<xsl:with-param name="fieldvalue" select="$groupfooter0" />
<xsl:with-param name="fieldtype" select="''" />
<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((#PdM)=$groupfooter0 or ((not(#PdM) or #PdM='') and $groupfooter0=' '))]" />
<xsl:with-param name="groupid" select="'0'" />
<xsl:with-param name="displaystyle" select="'auto'" />
<xsl:with-param name="showfooter" select="true()" />
<xsl:with-param name="showfootercolumn" select="false()" />
</xsl:call-template>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<xsl:variable name="dvt_GroupStyle" select="'none'" />
<tr style="display:{$dvt_GroupStyle}">
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(#ID))" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<xsl:variable name="monLoc" select="#Mon_x005F_x0020_Location"/>
<xsl:variable name="tuesLoc" select="#Tues_x005F_x0020_Location"/>
<xsl:variable name="wedLoc" select="#Wed_x005F_x0020_Location"/>
<xsl:variable name="thursLoc" select="#Thurs_x005F_x0020_Location"/>
<xsl:variable name="friLoc" select="#Fri_x005F_x0020_Location"/>
<xsl:variable name="listLocation" select="string-length(substring-before(#FileRef, 'sites'))"/>
<xsl:variable name="locationStripped">
<xsl:call-template name="SubstringBeforeLast">
<xsl:with-param name="String" select="#FileRef"/>
<xsl:with-param name="Char" select="'/'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="editURL" select="concat('/', substring($locationStripped, $listLocation+1), '/EditForm.aspx?ID=', #ID)"/>
<td class="ms-vb">
<a href="{$editURL}"
onclick="GoToLink(this);return false;"
target="_self">
<xsl:value-of select="substring-after(#UserName, ';#')" disable-output-escaping="yes"/>
</a>
</td><td class="ms-vb" title="{$monLoc}"><xsl:call-template name="color_reported">
<xsl:with-param name="status"><xsl:value-of select="#Mon_x005F_x0020_Status" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="#Mon_x005F_x0020_Status" /></td><td class="ms-vb" title="{$tuesLoc}"><xsl:call-template name="color_reported">
<xsl:with-param name="status"><xsl:value-of select="#Tues_x005F_x0020_Status" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="#Tues_x005F_x0020_Status" /></td><td class="ms-vb" title="{$wedLoc}"><xsl:call-template name="color_reported">
<xsl:with-param name="status"><xsl:value-of select="#Wed_x005F_x0020_Status" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="#Wed_x005F_x0020_Status" /></td><td class="ms-vb" title="{$thursLoc}"><xsl:call-template name="color_reported">
<xsl:with-param name="status"><xsl:value-of select="#Thurs_x005F_x0020_Status" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="#Thurs_x005F_x0020_Status" /></td><td class="ms-vb" title="{$friLoc}"><xsl:call-template name="color_reported">
<xsl:with-param name="status"><xsl:value-of select="#Fri_x005F_x0020_Status" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="#Fri_x005F_x0020_Status" /></td>
</tr>
</xsl:template>
<xsl:template name="dvt_1.groupheader0">
<xsl:param name="fieldtitle" />
<xsl:param name="fieldname" />
<xsl:param name="fieldvalue" />
<xsl:param name="fieldtype" />
<xsl:param name="nodeset" />
<xsl:param name="groupid" />
<xsl:param name="displaystyle" />
<xsl:param name="imagesrc" />
<xsl:param name="alttext" />
<xsl:param name="altname" />
<xsl:param name="hidedetail" />
<xsl:param name="showheader" />
<xsl:param name="showheadercolumn" />
<xsl:if test="$showheader" ddwrt:cf_ignore="1">
<tr id="group{$groupid}" style="display:{$displaystyle}">
<td class="ms-gb" style="background:#cccccc;" colspan="8">
<xsl:choose>
<xsl:when test="$groupid='0' or $groupid='9'">
<xsl:text></xsl:text>
</xsl:when>
<xsl:when test="$groupid='1'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
<xsl:when test="$groupid='2'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
<xsl:when test="$groupid='3'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
<xsl:when test="$groupid='4'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
<xsl:when test="$groupid='5'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
<xsl:when test="$groupid='6'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:if test="not($hidedetail)" ddwrt:cf_ignore="1">
<a href="javascript:" onclick="javascript:ExpGroupBy(this);return false;">
<img src="{$imagesrc}" border="0" alt="{$alttext}" name="{$altname}" /></a>
</xsl:if>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">&nbsp;</xsl:text>
<xsl:if test="$fieldvalue!='PMO'">
<b>
<xsl:value-of select="$fieldtitle" />
</b>
<xsl:if test="$fieldtitle">: </xsl:if>
</xsl:if>
<xsl:choose>
<xsl:when test="$fieldtype='url'">
<a href="{$fieldvalue}">
<xsl:value-of select="$fieldvalue" />
</a>
</xsl:when>
<xsl:when test="$fieldtype='user'">
<xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$fieldvalue" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:if>
</xsl:template>
<xsl:template name="dvt_1.groupfooter0">
<xsl:param name="fieldtitle" />
<xsl:param name="fieldname" />
<xsl:param name="fieldvalue" />
<xsl:param name="fieldtype" />
<xsl:param name="nodeset" />
<xsl:param name="groupid" />
<xsl:param name="displaystyle" />
<xsl:param name="showfooter" />
<xsl:param name="showfootercolumn" />
<xsl:if test="$showfooter" ddwrt:cf_ignore="1">
<tr id="group{$groupid}" style="display:{$displaystyle}">
<td class="ms-gb" style="background:#cccccc;" colspan="1" align="right">
<xsl:choose>
<xsl:when test="$groupid='0' or $groupid='9'"></xsl:when>
<xsl:when test="$groupid='1'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
<xsl:when test="$groupid='2'">
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:otherwise>
</xsl:choose>
<b><u>%Reported</u>
</b>
</td>
<td class="ms-gb">
<xsl:call-template name="color_present">
<xsl:with-param name="present"><xsl:value-of select="count($nodeset[#Mon_x005F_x0020_Status!='NR']) div count($nodeset)" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="format-number(count($nodeset[#Mon_x005F_x0020_Status!='NR']) div count($nodeset), '0%')" /></td>
<td class="ms-gb">
<xsl:call-template name="color_present">
<xsl:with-param name="present"><xsl:value-of select="count($nodeset[#Tues_x005F_x0020_Status!='NR']) div count($nodeset)" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="format-number(count($nodeset[#Tues_x005F_x0020_Status!='NR']) div count($nodeset), '0%')" /></td>
<td class="ms-gb">
<xsl:call-template name="color_present">
<xsl:with-param name="present"><xsl:value-of select="count($nodeset[#Wed_x005F_x0020_Status!='NR']) div count($nodeset)" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="format-number(count($nodeset[#Wed_x005F_x0020_Status!='NR']) div count($nodeset), '0%')" /></td>
<td class="ms-gb">
<xsl:call-template name="color_present">
<xsl:with-param name="present"><xsl:value-of select="count($nodeset[#Thurs_x005F_x0020_Status!='NR']) div count($nodeset)" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="format-number(count($nodeset[#Thurs_x005F_x0020_Status!='NR']) div count($nodeset), '0%')" /></td>
<td class="ms-gb">
<xsl:call-template name="color_present">
<xsl:with-param name="present"><xsl:value-of select="count($nodeset[#Fri_x005F_x0020_Status!='NR']) div count($nodeset)" /></xsl:with-param>
</xsl:call-template>
<xsl:value-of select="format-number(count($nodeset[#Fri_x005F_x0020_Status!='NR']) div count($nodeset), '0%')" /></td>
</tr>
</xsl:if>
</xsl:template>
<xsl:template name="dvt_1.footer">
<xsl:param name="Rows" />
<tr >
<td class="ms-vh" style="color:black; width: 129px;" align="right"><b><u>Org Totals</u></b></td>
<td class="ms-vh" colspan="8"></td>
</tr>
<xsl:variable name="presMon" select="count(/dsQueryResponse/Rows/Row[#Mon_x005F_x0020_Status='P'])" />
<xsl:variable name="presTues" select="count(/dsQueryResponse/Rows/Row[#Tues_x005F_x0020_Status='P'])" />
<xsl:variable name="presWed" select="count(/dsQueryResponse/Rows/Row[#Wed_x005F_x0020_Status='P'])" />
<xsl:variable name="presThurs" select="count(/dsQueryResponse/Rows/Row[#Thurs_x005F_x0020_Status='P'])" />
<xsl:variable name="presFri" select="count(/dsQueryResponse/Rows/Row[#Fri_x005F_x0020_Status='P'])" />
<tr >
<td class="ms-vb" align="right" style="width: 129px"><u>O/H</u></td>
<td class="ms-vb"><xsl:value-of select="$presMon" /></td>
<td class="ms-vb"><xsl:value-of select="$presTues" /></td>
<td class="ms-vb"><xsl:value-of select="$presWed" /></td>
<td class="ms-vb" style="width: 13px"><xsl:value-of select="$presThurs" /></td>
<td class="ms-vb"><xsl:value-of select="$presFri" /></td><td class="ms-vb" style="width: 26px">
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text>
</td></tr>
<xsl:variable name="offMon" select="count(/dsQueryResponse/Rows/Row[#Mon_x005F_x0020_Status='O'])" />
<xsl:variable name="offTues" select="count(/dsQueryResponse/Rows/Row[#Tues_x005F_x0020_Status='O'])" />
<xsl:variable name="offWed" select="count(/dsQueryResponse/Rows/Row[#Wed_x005F_x0020_Status='O'])" />
<xsl:variable name="offThurs" select="count(/dsQueryResponse/Rows/Row[#Thurs_x005F_x0020_Status='O'])" />
<xsl:variable name="offFri" select="count(/dsQueryResponse/Rows/Row[#Fri_x005F_x0020_Status='O'])" />
<xsl:if test="($offMon + $offTues + $offWed + $offThurs + $offFri) != 0">

xsl for table view in sharepoint

I have DataView web part that get data from two lists in SharePoint. I'm trying to change web part view but i do not know enough the xsl. my code is
<XSL>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:agg="http://schemas.microsoft.com/sharepoint/aggregatesource" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:param name="ManualRefresh"></xsl:param>
<xsl:param name="dvt_firstrow">1</xsl:param>
<xsl:param name="dvt_nextpagedata" />
<xsl:param name="dvt_groupfield" />
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:agg="http://schemas.microsoft.com/sharepoint/aggregatesource" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<xsl:choose>
<xsl:when test="($ManualRefresh = 'True')">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<xsl:call-template name="dvt_1"/>
</td>
<td width="1%" class="ms-vb" valign="top">
<img src="/_layouts/images/staticrefresh.gif" id="ManualRefresh" border="0" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" alt="Click here to refresh the dataview."/>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="dvt_1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[#_x041f__x043e__x0442__x0432__x04 = 'Da']"/>
<xsl:variable name="dvt_RowCount" select="count($Rows)"/>
<xsl:variable name="RowLimit" select="10" />
<xsl:variable name="FirstRow" select="$dvt_firstrow" />
<xsl:variable name="LastRow">
<xsl:choose>
<xsl:when test="($FirstRow + $RowLimit - 1) > $dvt_RowCount"><xsl:value-of select="$dvt_RowCount" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$FirstRow + $RowLimit - 1" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
<xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0"/>
<xsl:choose>
<xsl:when test="$dvt_IsEmpty">
<xsl:call-template name="dvt_1.empty"/>
</xsl:when>
<xsl:otherwise>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr >
<th style="width: 261px; text-align:center">Sredstvo koje se izdaje</th>
<th style="width: 164px; text-align:center">Izdata sredstva - trenutno stanje</th>
<th style="width: 240px; text-align:center">Količina - početno stanje</th>
</tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
<xsl:with-param name="FirstRow" select="$FirstRow" />
<xsl:with-param name="LastRow" select="$LastRow" />
</xsl:call-template>
</table>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="dvt_1.commandfooter">
<xsl:with-param name="FirstRow" select="$FirstRow" />
<xsl:with-param name="LastRow" select="$LastRow" />
<xsl:with-param name="RowLimit" select="$RowLimit" />
<xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" />
<xsl:with-param name="RealLastRow" select="number(ddwrt:NameChanged('',-100))" />
</xsl:call-template>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<xsl:variable name="dvt_Rows"><root>
<xsl:for-each select="$Rows">
<xsl:sort select="#_x0418__x0437__x0434__x0430__x04" order="ascending" />
<xsl:if test="(position() >= $FirstRow and position() <= $LastRow)"><xsl:copy-of select="." /></xsl:if>
</xsl:for-each>
</root></xsl:variable>
<xsl:for-each select="$Rows">
<xsl:sort select="#_x0418__x0437__x0434__x0430__x04" order="ascending" />
<xsl:variable name="NewGroup_0">
<xsl:choose>
<xsl:when test="not ($dvt_groupfield)"><xsl:value-of select="ddwrt:NameChanged(string(#_x0418__x0437__x0434__x0430__x04), 0)" /></xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="0" />
<xsl:when test="not($dvt_groupfield) and (not($NewGroup_0='') and position() >= $FirstRow and position() <= $LastRow or ($FirstRow = position()))">
<xsl:variable name="groupheader0">
<xsl:choose>
<xsl:when test="not (#_x0418__x0437__x0434__x0430__x04) and (#_x0418__x0437__x0434__x0430__x04) != false()"><xsl:value-of select="' '" /></xsl:when>
<xsl:otherwise><xsl:value-of select="#_x0418__x0437__x0434__x0430__x04" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="not ((position()=1) or (position()=$FirstRow))"></xsl:if>
<xsl:call-template name="dvt_1.groupheader0">
<xsl:with-param name="fieldtitle">Sredstvo koje se izdaje</xsl:with-param>
<xsl:with-param name="fieldname">_x0418__x0437__x0434__x0430__x04</xsl:with-param>
<xsl:with-param name="fieldvalue" select="$groupheader0" />
<xsl:with-param name="fieldtype" select="'text'" />
<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((#_x0418__x0437__x0434__x0430__x04)=$groupheader0 or ((not(#_x0418__x0437__x0434__x0430__x04) or #_x0418__x0437__x0434__x0430__x04='') and $groupheader0=' '))]" />
<xsl:with-param name="groupid" select="'0'" />
<xsl:with-param name="displaystyle" select="'auto'" />
<xsl:with-param name="imagesrc" select="'/_layouts/images/plus.gif'" />
<xsl:with-param name="alttext" select="'expand'" />
<xsl:with-param name="altname" select="'collapse'" />
<xsl:with-param name="hidedetail" select="true()" />
<xsl:with-param name="showheader" select="true()" />
<xsl:with-param name="showheadercolumn" select="false()" />
</xsl:call-template>
</xsl:when>
</xsl:choose>
<xsl:variable name="BreakOut">
<xsl:choose>
<xsl:when test="not($dvt_groupfield) and position()=$LastRow+1"><xsl:value-of select="ddwrt:NameChanged('', -1)" /></xsl:when>
<xsl:otherwise>BreakOut</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="dvt_KeepItemsTogether" select="false()" />
<xsl:variable name="dvt_HideGroupDetail" select="true()" />
<xsl:if test="(position() >= $FirstRow and position() <= $LastRow) or $dvt_KeepItemsTogether">
<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
<xsl:call-template name="dvt_1.rowview" />
</xsl:if>
</xsl:if>
<xsl:choose>
<xsl:when test="0" />
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<xsl:variable name="dvt_GroupStyle" select="'none'" />
<tr style="display:{$dvt_GroupStyle}">
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if><td class="ms-vb">
<xsl:value-of select="#_x0418__x0437__x0434__x0430__x04" disable-output-escaping="yes" /></td>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"></span>
</td>
</xsl:if><td class="ms-vb">
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text>
</td><td class="ms-vb">
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text>
</td></tr>
</xsl:template>
<xsl:template name="dvt_1.empty">
<xsl:variable name="dvt_ViewEmptyText">There are no items to show in this view.</xsl:variable>
<table border="0" width="100%">
<tr>
<td class="ms-vb">
<xsl:value-of select="$dvt_ViewEmptyText"/>
</td>
</tr>
</table>
</xsl:template>
<xsl:template name="dvt_1.commandfooter">
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<xsl:param name="RowLimit" />
<xsl:param name="dvt_RowCount" />
<xsl:param name="RealLastRow" />
<table cellspacing="0" cellpadding="4" border="0" width="100%">
<tr>
<xsl:if test="$FirstRow > 1 or $LastRow < $dvt_RowCount">
<xsl:call-template name="dvt_1.navigation">
<xsl:with-param name="FirstRow" select="$FirstRow" />
<xsl:with-param name="LastRow" select="$LastRow" />
<xsl:with-param name="RowLimit" select="$RowLimit" />
<xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" />
<xsl:with-param name="RealLastRow" select="$RealLastRow" />
</xsl:call-template>
</xsl:if>
</tr>
</table>
</xsl:template>
<xsl:template name="dvt_1.navigation">
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<xsl:param name="RowLimit" />
<xsl:param name="dvt_RowCount" />
<xsl:param name="RealLastRow" />
<xsl:variable name="PrevRow">
<xsl:choose>
<xsl:when test="$FirstRow - $RowLimit < 1">1</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$FirstRow - $RowLimit" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="LastRowValue">
<xsl:choose>
<xsl:when test="$LastRow > $RealLastRow">
<xsl:value-of select="$LastRow"></xsl:value-of>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$RealLastRow"></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="NextRow">
<xsl:value-of select="$LastRowValue + 1"></xsl:value-of>
</xsl:variable>
<td nowrap="nowrap" class="ms-paging" align="right">
<xsl:if test="$dvt_firstrow > 1" ddwrt:cf_ignore="1">
<a>
<xsl:attribute name="href">javascript: <xsl:value-of select="ddwrt:GenFireServerEvent('dvt_firstrow={1}')" />;</xsl:attribute>
Start</a>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
<a>
<xsl:attribute name="href">javascript: <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={',$PrevRow,'}'))" />;</xsl:attribute>
<img src="/_layouts/images/prev.gif" border="0" alt="Previous" />
</a>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&nbsp;</xsl:text>
</xsl:if>
<xsl:value-of select="$FirstRow" />
- <xsl:value-of select="$LastRowValue" />
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">&nbsp;</xsl:text>
<xsl:if test="$LastRowValue < $dvt_RowCount or string-length($dvt_nextpagedata)!=0" ddwrt:cf_ignore="1">
<a>
<xsl:attribute name="href">javascript: <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={',$NextRow,'}'))" />;</xsl:attribute>
<img src="/_layouts/images/next.gif" border="0" alt="Next" />
</a>
</xsl:if>
</td>
</xsl:template>
<xsl:variable name="dvt_2_automode">0</xsl:variable>
<xsl:decimal-format decimal-separator="," grouping-separator="." name="lcid3098" />
<xsl:template name="dvt_1.groupheader0">
<xsl:param name="fieldtitle" />
<xsl:param name="fieldname" />
<xsl:param name="fieldvalue" />
<xsl:param name="fieldtype" />
<xsl:param name="nodeset" />
<xsl:param name="groupid" />
<xsl:param name="displaystyle" />
<xsl:param name="imagesrc" />
<xsl:param name="alttext" />
<xsl:param name="altname" />
<xsl:param name="hidedetail" />
<xsl:param name="showheader" />
<xsl:param name="showheadercolumn" />
<xsl:if test="$showheader" ddwrt:cf_ignore="1">
<tr id="group{$groupid}" style="display:{$displaystyle}">
<td class="ms-gb" colspan="0" style="height: 1px; width: 261px;">
<xsl:if test="not($hidedetail)" ddwrt:cf_ignore="1">
<a href="javascript:" onclick="javascript:ExpGroupBy(this);return false;">
<img src="{$imagesrc}" border="0" alt="{$alttext}" name="{$altname}" /></a>
</xsl:if>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">&nbsp;</xsl:text>
<xsl:choose>
<xsl:when test="$fieldtype='url'">
<a href="{$fieldvalue}">
<xsl:value-of select="$fieldvalue" />
</a>
</xsl:when>
<xsl:when test="$fieldtype='user'">
<xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$fieldvalue" disable-output-escaping="yes" /> </xsl:otherwise>
</xsl:choose>
</td>
<td style="height: 1px; width: 164px; text-align:center;"><xsl:value-of disable-output-escaping="yes" select="count($nodeset)" /></td>
<!-- <td style="height: 1px"><xsl:for-each select="/dsQueryResponse/Rows/Row"><xsl:value-of select="#_x041a__x043e__x043b__x0438__x04" disable-output-escaping="yes" /></xsl:for-each></td>
--><td style="height: 1px"><xsl:for-each select="/dsQueryResponse/Rows/Row"><xsl:value-of select="#_x041a__x043e__x043b__x0438__x04" /></xsl:for-each></td>
</tr>
</xsl:if>
</xsl:template>
</xsl:stylesheet> </XSL>
list should look like Figure 1, and I get my results as the code in Figure 2.
So, each field in the column kolicina - pocetno stanje get results for all, should be as in Figure 1 in the column Kolicina
Figure1
Figure2

Display alternate style class in XSLT

I want to display alternate style class in XSLT.
Here is my code:
<xsl:variable name="oddEven" select="1" />
<xsl:for-each select="//ProfileBR">
<xsl:variable name="i" select="((position() - 1) * 2) + 1" />
<xsl:variable name="iBR" select="substring(//BRValue,$i,1)" />
<xsl:variable name="jBR" select="substring(//BRValue,$i+1,1)" />
<xsl:if test="$iBR='1' or $jBR='1'">
<xsl:choose>
<xsl:when test="$oddEven='1'">
<tr class="sbListOddCell">
<xsl:if test="$iBR=0">
<td></td>
</xsl:if>
<xsl:call-template name="JobInfoSection">
<xsl:with-param name="ii" select="$i"/>
<xsl:with-param name="jj" select="$i+1"/>
<xsl:with-param name="iiBR" select="$iBR"/>
<xsl:with-param name="jjBR" select="$jBR"/>
</xsl:call-template>
<xsl:if test="$jBR=0">
<td></td>
</xsl:if>
</tr>
<xsl:variable name="oddEven" select="0" />
</xsl:when>
<xsl:otherwise>
<tr class="sbListEvenCell">
<xsl:if test="$iBR=0">
<td></td>
</xsl:if>
<xsl:call-template name="JobInfoSection">
<xsl:with-param name="ii" select="$i"/>
<xsl:with-param name="jj" select="$i+1"/>
<xsl:with-param name="iiBR" select="$iBR"/>
<xsl:with-param name="jjBR" select="$jBR"/>
</xsl:call-template>
<xsl:if test="$jBR=0">
<td></td>
</xsl:if>
</tr>
<xsl:variable name="oddEven" select="1" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
Currently the oddEven logic is not working as the value does not persist.
Note: The position is not at all related with the display. If the condition satisfy than only display the <tr> else not.
I think using the CSS will be better for this case or may be Javascript ..
table tr:nth-child(odd) td{
}
table tr:nth-child(even) td{
}
I think you can also use a counter if you have changed the loop style to be a recursive like this
<xsl:template name="loop">
<xsl:param name="other param"/>
<xsl:param name="count"/>
<!-- logic then recurse and pass the counter with $counter + 1-->
</xsl:template>
As you can each time path the param with a new value.
I hope this could help!

Please suggest for XSLT code for Table rowspan and colspan issues

<article>
<table id="tbl1">
<caption><p>Table 1. Sample Table</p></caption>
<thead>
<tr>
<td colspan="3">I</td>
<td colspan="4">II</td>
</tr>
<tr>
<td>Sl. No.</td>
<td>Name</td>
<td>Place</td>
<td>Subject 1</td>
<td>Subject 2</td>
<td>Subject 3</td>
<td>Grade</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3">1</td>
<td colspan="2">Kishan</td>
<td>95</td>
<td>96</td>
<td rowspan="2">97</td>
<td>A</td>
</tr>
<tr>
<td>Kishan</td>
<td>Bangalore</td>
<td>94</td>
<td>96</td>
<td>A</td>
</tr>
<tr>
<td>Likhith</td>
<td>Bhadravathi</td>
<td>94</td>
<td>94</td>
<td>99</td>
<td>A</td>
</tr>
</tbody>
</table>
</article>
Required OutPut: If colspan is 2 is coded in second cell, then third should not be there, next cell name should be "colname="3" (start Index is 0). Same for rowspan, if present row's first cell having rowspan="3", then next two rows should not have colname="0", those next two rows start cells will have the name="1" (start index is 0, thats why 1 means second cell). Please suggest for the XSLT coding two address both rowspan and colspan present in same table.
<article>
<table id="tbl1">
<caption><p>Table 1. Sample Table</p></caption>
<thead>
<tr>
<td colname="0:0">I</td>
<td colname="0:3">II</td>
</tr>
<tr>
<td colname="1:0">Sl. No.</td>
<td colname="1:1">Name</td>
<td colname="1:2">Place</td>
<td colname="1:3">Subject 1</td>
<td colname="1:4">Subject 2</td>
<td colname="1:5">Subject 3</td>
<td colname="1:6">Grade</td>
</tr>
</thead>
<tbody>
<tr>
<td colname="2:0">1</td>
<td colname="2:1">Kishan</td>
<td colname="2:3">95</td>
<td colname="2:4">96</td>
<td colname="2:5">97</td>
<td colname="2:6">A</td>
</tr>
<tr>
<td colname="3:1">Kishan</td>
<td colname="3:2">Bangalore</td>
<td colname="3:3">94</td>
<td colname="3:4">96</td>
<td colname="3:6">A</td>
</tr>
<tr>
<td colname="4:1">Likhith</td>
<td colname="4:2">Bhadravathi</td>
<td colname="4:3">94</td>
<td colname="4:4">94</td>
<td colname="4:5">99</td>
<td colname="4:6">A</td>
</tr>
</tbody>
</table>
</article>
XSLT code from StackOverFlow site:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--rowspan in table with xslt-->
<xsl:template match="TABLE2">
<tbody>
<xsl:call-template name="processRows">
<xsl:with-param name="rows" select="ROW"/>
</xsl:call-template>
</tbody>
</xsl:template>
<xsl:template name="processRows">
<xsl:param name="rows"/>
<xsl:param name="index" select="1"/>
<!-- Bit vector for the columns -->
<xsl:param name="col1" select="0"/>
<xsl:param name="col2" select="0"/>
<xsl:param name="col3" select="0"/>
<xsl:param name="col4" select="0"/>
<xsl:param name="col5" select="0"/>
<xsl:param name="col6" select="0"/>
<xsl:variable name="cellsBefore2">
<xsl:choose>
<xsl:when test="$col1 > 0">0</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cellsBefore3">
<xsl:choose>
<xsl:when test="$col2 > 0">
<xsl:value-of select="$cellsBefore2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$cellsBefore2 + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cellsBefore4">
<xsl:choose>
<xsl:when test="$col3 > 0">
<xsl:value-of select="$cellsBefore3"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$cellsBefore3 + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cellsBefore5">
<xsl:choose>
<xsl:when test="$col4 > 0">
<xsl:value-of select="$cellsBefore4"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$cellsBefore4 + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cellsBefore6">
<xsl:choose>
<xsl:when test="$col5 > 0">
<xsl:value-of select="$cellsBefore5"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$cellsBefore5 + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<row>
<xsl:if test="$col1 = 0">
<entry colname="1">
<xsl:value-of select="$rows[$index]/CELL[1]/text()"/>
</entry>
</xsl:if>
<xsl:if test="$col2 = 0">
<entry colname="2">
<xsl:value-of select="$rows[$index]/CELL[$cellsBefore2 + 1]/text()"/>
</entry>
</xsl:if>
<xsl:if test="$col3 = 0">
<entry colname="3">
<xsl:value-of select="$rows[$index]/CELL[$cellsBefore3 + 1]/text()"/>
</entry>
</xsl:if>
<xsl:if test="$col4 = 0">
<entry colname="4">
<xsl:value-of select="$rows[$index]/CELL[$cellsBefore4 + 1]/text()"/>
</entry>
</xsl:if>
<xsl:if test="$col5 = 0">
<entry colname="5">
<xsl:value-of select="$rows[$index]/CELL[$cellsBefore5 + 1]/text()"/>
</entry>
</xsl:if>
<xsl:if test="$col6 = 0">
<entry colname="6">
<xsl:value-of select="$rows[$index]/CELL[$cellsBefore6 + 1]/text()"/>
</entry>
</xsl:if>
</row>
<xsl:if test="$index < count($rows)">
<xsl:call-template name="processRows">
<xsl:with-param name="rows" select="$rows"/>
<xsl:with-param name="index" select="$index + 1"/>
<xsl:with-param name="col1">
<xsl:choose>
<xsl:when test="$col1 > 0">
<xsl:value-of select="$col1 - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($rows[$index]/CELL[1]/#ROWSPAN) - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="col2">
<xsl:choose>
<xsl:when test="$col2 > 0">
<xsl:value-of select="$col2 - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($rows[$index]/CELL[$cellsBefore2 + 1]/#ROWSPAN) - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="col3">
<xsl:choose>
<xsl:when test="$col3 > 0">
<xsl:value-of select="$col3 - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($rows[$index]/CELL[$cellsBefore3 + 1]/#ROWSPAN) - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="col4">
<xsl:choose>
<xsl:when test="$col4 > 0">
<xsl:value-of select="$col4 - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($rows[$index]/CELL[$cellsBefore4 + 1]/#ROWSPAN) - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="col5">
<xsl:choose>
<xsl:when test="$col5 > 0">
<xsl:value-of select="$col5 - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($rows[$index]/CELL[$cellsBefore5 + 1]/#ROWSPAN) - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="col6">
<xsl:choose>
<xsl:when test="$col6 > 0">
<xsl:value-of select="$col6 - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($rows[$index]/CELL[$cellsBefore6 + 1]/#ROWSPAN) - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
This is not at all simple. Basically, you are asking how to render an HTML table visually, by positioning each cell on a (equi-spaced) x-y grid of rows and columns.
This is complex, because the position of each cell depends not only on the width (colspan) of the preceding cells in the same row, but also on the position of cells in preceding rows that span more than one row. This position is not known before the preceding cells themselves have been processed - so this is a giant render-as-you-go cascading operation.
Due to this complexity, I suggest solving the basic problem in isolation first, before introducing additional constraints (e.g. separate header rows or numbers starting from 0).
For testing, I have used the following table1 as the input:
<table border="1">
<tr>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
</tr>
<tr>
<td rowspan="2">A</td>
<td colspan="2">B</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
</tr>
<tr>
<td>E</td>
<td rowspan="2" colspan="2">F</td>
</tr>
<tr>
<td>G</td>
</tr>
<tr>
<td colspan="3">H</td>
</tr>
</table>
Applying the folowing stylesheet:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/table">
<table>
<xsl:text>
</xsl:text>
<xsl:call-template name="generate-rows">
<xsl:with-param name="current-row" select="1"/>
<xsl:with-param name="last-row" select="count(tr)"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="generate-rows">
<xsl:param name="current-row"/>
<xsl:param name="last-row"/>
<xsl:param name="result" select="some-dummy-node-to-make-this-a-node"/>
<!-- append current-row to previous result -->
<xsl:variable name="new-result">
<xsl:copy-of select="$result"/>
<row num="{$current-row}">
<xsl:text>
</xsl:text>
<!-- generate cells for current-row -->
<xsl:call-template name="generate-cells">
<xsl:with-param name="current-row" select="$current-row"/>
<xsl:with-param name="current-cell" select="1"/>
<xsl:with-param name="x" select="1"/>
<xsl:with-param name="last-cell" select="count(tr[$current-row]/td)"/>
<xsl:with-param name="previous-rows" select="$result"/>
</xsl:call-template>
</row>
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:choose>
<xsl:when test="$current-row < $last-row">
<!-- recursive call -->
<xsl:call-template name="generate-rows">
<xsl:with-param name="current-row" select="$current-row + 1"/>
<xsl:with-param name="last-row" select="$last-row"/>
<xsl:with-param name="result" select="$new-result"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- return result -->
<xsl:copy-of select="$new-result"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="generate-cells">
<xsl:param name="current-row"/>
<xsl:param name="current-cell"/>
<xsl:param name="x"/>
<xsl:param name="last-cell"/>
<xsl:param name="previous-rows"/>
<xsl:variable name="my-cell" select="tr[$current-row]/td[$current-cell]" />
<xsl:choose>
<!-- if there's a collision, move one place to the right -->
<xsl:when test="exsl:node-set($previous-rows)/row/cell[#x <= $x and #x + #width > $x and #y + #height > $current-row]">
<xsl:call-template name="generate-cells">
<xsl:with-param name="current-row" select="$current-row"/>
<xsl:with-param name="current-cell" select="$current-cell"/>
<xsl:with-param name="x" select="$x + 1"/>
<xsl:with-param name="last-cell" select="$last-cell"/>
<xsl:with-param name="previous-rows" select="$previous-rows"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="width">
<xsl:choose>
<xsl:when test="$my-cell/#colspan">
<xsl:value-of select="$my-cell/#colspan"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="height">
<xsl:choose>
<xsl:when test="$my-cell/#rowspan">
<xsl:value-of select="$my-cell/#rowspan"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:text> </xsl:text>
<cell num="{$current-cell}" y="{$current-row}" x="{$x}" width="{$width}" height="{$height}">
<xsl:value-of select="$my-cell"/>
</cell>
<xsl:text>
</xsl:text>
<xsl:if test="$current-cell < $last-cell">
<xsl:call-template name="generate-cells">
<xsl:with-param name="current-row" select="$current-row"/>
<xsl:with-param name="current-cell" select="$current-cell + 1"/>
<xsl:with-param name="x" select="$x + $width"/>
<xsl:with-param name="last-cell" select="count(tr[$current-row]/td)"/>
<xsl:with-param name="previous-rows" select="$previous-rows"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
produces the following result:
<?xml version="1.0" encoding="UTF-8"?>
<table>
<row num="1">
<cell num="1" y="1" x="1" width="1" height="1">Column 1</cell>
<cell num="2" y="1" x="2" width="1" height="1">Column 2</cell>
<cell num="3" y="1" x="3" width="1" height="1">Column 3</cell>
</row>
<row num="2">
<cell num="1" y="2" x="1" width="1" height="2">A</cell>
<cell num="2" y="2" x="2" width="2" height="1">B</cell>
</row>
<row num="3">
<cell num="1" y="3" x="2" width="1" height="1">C</cell>
<cell num="2" y="3" x="3" width="1" height="1">D</cell>
</row>
<row num="4">
<cell num="1" y="4" x="1" width="1" height="1">E</cell>
<cell num="2" y="4" x="2" width="2" height="2">F</cell>
</row>
<row num="5">
<cell num="1" y="5" x="1" width="1" height="1">G</cell>
</row>
<row num="6">
<cell num="1" y="6" x="1" width="3" height="1">H</cell>
</row>
</table>
As you can see, the x-y positioning of each cell corresponds to the visual rendering of the original table in a browser:
--
1. From http://en.wikipedia.org/wiki/Help:Table
For XSLT 2.0:
Change the stylesheet declaration to:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Change line #66 to:
<xsl:when test="$previous-rows/row/cell[#x <= $x and #x + #width > $x and #y + #height > $current-row]">

XSLT Confusion with xsl:apply-templates

I have an XML file with this format:
<?xml version="1.0" encoding="utf-8" ?>
<OpacResult>
<valueObjects class="list">
<Catalog>
<notes>
Daily newsletter available via e-mail.
IP authenticated. Login not needed within firm.
</notes>
<title>Health law360. </title>
<url>http://health.law360.com/</url>
<catalogTitles class="list">
<CatalogTitle>
<uuid>e5e2bc53ac1001f808cddc29f93ecad8</uuid>
<timeChanged class="sql-timestamp">2010-12-14 09:17:10.707</timeChanged>
<timeEntered class="sql-timestamp">2010-12-14 09:17:10.707</timeEntered>
<whoChanged>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoChanged>
<whoEntered>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoEntered>
<updateSearchIndex>true</updateSearchIndex>
<corpId>RopesGray</corpId>
<catalogUuid>a20b6b4bac1001f86d28280ed0ebeb9e</catalogUuid>
<type>O</type>
<title>Law 360. Health law.</title>
</CatalogTitle>
<CatalogTitle>
<uuid>e5e2bc53ac1001f808cddc299ddfe49d</uuid>
<timeChanged class="sql-timestamp">2010-12-14 09:17:10.707</timeChanged>
<timeEntered class="sql-timestamp">2010-12-14 09:17:10.707</timeEntered>
<whoChanged>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoChanged>
<whoEntered>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoEntered>
<updateSearchIndex>true</updateSearchIndex>
<corpId>RopesGray</corpId>
<catalogUuid>a20b6b4bac1001f86d28280ed0ebeb9e</catalogUuid>
<type>O</type>
<title>Health law 360</title>
</CatalogTitle>
<CatalogTitle>
<uuid>e5e2bc53ac1001f808cddc29ec1d959b</uuid>
<timeChanged class="sql-timestamp">2010-12-14 09:17:10.707</timeChanged>
<timeEntered class="sql-timestamp">2010-12-14 09:17:10.707</timeEntered>
<whoChanged>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoChanged>
<whoEntered>B23DE2FFE8DD49B0B0A03D1FEB3E7DA2</whoEntered>
<updateSearchIndex>true</updateSearchIndex>
<corpId>RopesGray</corpId>
<catalogUuid>a20b6b4bac1001f86d28280ed0ebeb9e</catalogUuid>
<type>O</type>
<title>Health law three hundred sixty</title>
</CatalogTitle>
</catalogTitles>
<catalogUrls class="list"/>
<gmd>
<uuid>f8f123acc0a816070192e296a6a71715</uuid>
<timeChanged class="sql-timestamp">2006-10-10 15:23:37.813</timeChanged>
<timeEntered class="sql-timestamp">2005-01-27 00:00:00.0</timeEntered>
<whoChanged>25db9fcd3fd247f4a20485b40cc134ad</whoChanged>
<whoEntered>user</whoEntered>
<updateSearchIndex>true</updateSearchIndex>
<corpId>RopesGray</corpId>
<isRuleDefault>false</isRuleDefault>
<ruleName>text</ruleName>
<term>electronic resource</term>
<preferCollection>false</preferCollection>
<isTechnicalManual>false</isTechnicalManual>
<sip2IsMagnetic>false</sip2IsMagnetic>
</gmd>
<issues class="list"/>
</Catalog>
</valueObjects>
</OpacResult>
As you can see, there are other elements under sibling nodes, but I don't care about these and only want to see the first one.
I'm using this code to call a template with the string of desired elements as the parameter
and a template to loop through the asterisk-delimited string parameter: (title*url*notes*)
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="columns" />
<xsl:template match="/OpacResult/valueObjects">
<html>
<body>
<table border="1">
<!-- Header row -->
<tr>
<xsl:call-template name="print-headers">
<xsl:with-param name="columns" select="$columns"/>
</xsl:call-template>
</tr>
<!-- Value rows -->
<xsl:for-each select="Catalog">
<tr>
<xsl:call-template name="print-values">
<xsl:with-param name="columns" select="$columns"/>
</xsl:call-template>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<!-- Split up string of column names and create header field names based on element names-->
<xsl:template name="print-headers">
<xsl:param name="columns"/>
<xsl:variable name="newList" select="$columns"/>
<xsl:variable name="first" select="substring-before($newList, '*')" />
<xsl:variable name="remaining" select="substring-after($newList, '*')" />
<th>
<xsl:apply-templates select="Catalog/*[name()=$first]">
<xsl:with-param name="header">true</xsl:with-param>
</xsl:apply-templates>
</th>
<xsl:if test="$remaining">
<xsl:call-template name="print-headers">
<xsl:with-param name="columns" select="$remaining"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="print-values">
<xsl:param name="columns"/>
<xsl:variable name="newList" select="$columns"/>
<xsl:variable name="first" select="substring-before($newList, '*')" />
<xsl:variable name="remaining" select="substring-after($newList, '*')" />
<td>
<xsl:apply-templates select="Catalog/*[name()=$first]"/>
</td>
<xsl:if test="$remaining">
<xsl:call-template name="print-values">
<xsl:with-param name="columns" select="$remaining"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="title">
<xsl:param name="header"/>
<xsl:choose>
<xsl:when test="$header='true'">
<xsl:text>Title</xsl:text>
</xsl:when>
<xsl:otherwise>
<a>
<xsl:attribute name="href">
<xsl:value-of select="//*[name()='url']"/>
</xsl:attribute>
<xsl:value-of select="//*[name()='title']"/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="url">
<xsl:param name="header"/>
<xsl:choose>
<xsl:when test="$header='true'">
<xsl:text>URL</xsl:text>
</xsl:when>
<xsl:otherwise>
<a>
<xsl:attribute name="href">
<xsl:value-of select="//*[name()='url']"/>
</xsl:attribute>
<xsl:value-of select="//*[name()='url']"/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="notes">
<xsl:param name="header"/>
<xsl:choose>
<xsl:when test="$header='true'">
<xsl:text>Notes</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//*[name()='notes']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="holdingNotes">
<xsl:param name="header"/>
<xsl:choose>
<xsl:when test="$header='true'">
<xsl:text>Holding Notes</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//*[name()='holdingNotes']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="relatedUrl">
<xsl:param name="header"/>
<xsl:choose>
<xsl:when test="$header='true'">
<xsl:text>Related URL</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//*[name()='relatedUrl']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="bibliographicType/hasDataFile">
<xsl:param name="header"/>
<xsl:choose>
<xsl:when test="$header='true'">
<xsl:text>File</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="Catalog/*[name()='hasDataFile']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The only way I can access this template is to use the //*[name()=$first] syntax to extract the value of the element based on the name from the $first parameter.
Any help is greatly appreciated. Thanks very much in advance. Not including the full XML as there are thousands of lines of unnecessary text.
This stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h="header"
exclude-result-prefixes="h">
<h:h>
<title>Title</title>
<url>URL</url>
<notes>Notes</notes>
</h:h>
<xsl:param name="pColumns" select="'title url notes'"/>
<xsl:template match="/OpacResult/valueObjects">
<html>
<body>
<table border="1">
<tr>
<xsl:apply-templates
select="document('')/*/h:h"
mode="filter"/>
</tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Catalog">
<tr>
<xsl:call-template name="filter"/>
</tr>
</xsl:template>
<xsl:template match="h:h/*">
<th>
<xsl:value-of select="."/>
</th>
</xsl:template>
<xsl:template match="Catalog/*">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="node()" mode="filter" name="filter">
<xsl:apply-templates select="*[contains(
concat(' ',$pColumns,' '),
concat(' ',name(),' '))]">
<xsl:sort select="substring-before(
concat(' ',$pColumns,' '),
concat(' ',name(),' '))"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Output:
<html>
<body>
<table border="1">
<tr>
<th>Title</th>
<th>URL</th>
<th>Notes</th>
</tr>
<tr>
<td>Health law360. </td>
<td>http://health.law360.com/</td>
<td> Daily newsletter available via e-mail.
IP authenticated. Login not needed within firm. </td>
</tr>
</table>
</body>
</html>
Note: Inline data for headers, pseudo sequence parameter for filtering and sorting, modes not for processing the same element in different way but for processing different elements in the same way also.
I've found a solution, but I'm sure it's not the best way to do it. Within the templates for each of my expected fields, I have added:
<xsl:if test=position()=1">
.. process data here ..
</xsl:if>
Ideally, there would be a way to tell this to process only the first element it finds:
<th>
<xsl:apply-templates select="//*[name()=$first]">
<xsl:with-param name="header">true</xsl:with-param>
</xsl:apply-templates>
</th>
Edit: As I suspected, this will not work when there is more than one Catalog element to parse. So instead of grabbing the first element for each catalog parent element, it's grabbing the first element in the document every time