I've the below XML.
<toc-item>
<toc-title>
6A. <content-style font-style="italic">(Repealed 64 of 1989 s.9)
</content-style>
</toc-title>
<toc-pg>U2/6A</toc-pg>
</toc-item>
and i'm running with the below XSLT.
<xsl:template name="toc" match="toc">
<div class="toc">
<div class="toc-part">
<table class="toc-div">
<tbody>
<tr>
<td>
<xsl:for-each select="toc-part/toc-div/toc-item">
<xsl:call-template name="toc-item"/>
</xsl:for-each>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</xsl:template>
<xsl:template name="toc-item" match="toc-item">
<xsl:variable name="tocpg">
<xsl:value-of select="concat('P',normalize-space(current()/toc-pg/text()))"/>
</xsl:variable>
<xsl:variable name="tocpgtag">
<xsl:choose>
<xsl:when test="contains($tocpg,'.')">
<xsl:value-of select="translate($tocpg,'.', '-')"/>
</xsl:when>
<xsl:when test="contains($tocpg,'/')">
<xsl:value-of select="translate($tocpg,'/', '-')"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:value-of select="ancestor::chapter[1]/#num"/>
</xsl:variable>
<xsl:variable name="nu">
<xsl:number format="I."/>
</xsl:variable>
<xsl:variable name="Brac">
<xsl:call-template name="get_number_type">
<xsl:with-param name="number_string" select="./#num"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="NewL">
<xsl:value-of select="normalize-space($chapternumber)"/>
</xsl:variable>
<xsl:variable name="size">
<xsl:value-of select="fn:string-length($NewL)"/>
</xsl:variable>
<xsl:variable name="newNum">
<xsl:choose>
<xsl:when test="$size=1">
<xsl:value-of select="concat('0',normalize-space($NewL))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space($NewL)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="d">
<xsl:value-of select="concat('toc-item-',$ThisDocument//ntw:nums[#num=1]/#word,'-level')"/>
</xsl:variable>
<xsl:variable name="new">
<xsl:value-of select="concat('er:#HKWBV1_ORD_',$newNum,'/',$tocpgtag)"/>
</xsl:variable>
<table class="toc-item-first-level">
<tbody>
<tr>
<xsl:choose>
<xsl:when test="./toc-pg">
<xsl:choose>
<xsl:when test="fn:contains(./toc-title,'.')">
<td class="toc-item-num">
<xsl:value-of select="concat(substring-before(./toc-title,'.'),'.')"/>
</td>
</xsl:when>
<xsl:otherwise>
<td colspan="2" align="left" class="padtit">
<xsl:value-of select="./toc-title"/>
</td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="fn:contains(./toc-title,'.')">
<td class="toc-title">
<xsl:apply-templates select="./toc-title" mode="x"/>
</td>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
<td class="toc-pg">
<xsl:choose>
<xsl:when test="contains(./toc-pg,'.')">
<xsl:value-of select="normalize-space(current()/toc-pg)"/>
</xsl:when>
<xsl:when test="contains(./toc-pg,'/')">
<a href="{$new}">
<xsl:value-of select="normalize-space(current()/toc-pg)"/>
</a>
</xsl:when>
<xsl:otherwise>
<a href="{concat('#pg_',toc-pg)}">
<xsl:value-of select="normalize-space(current()/toc-pg)"/>
</a>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:when>
<xsl:otherwise>
<td align="center" colspan="3">
<span class="font-style-bold">
<xsl:apply-templates select="./toc-title"/>
</span>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</tbody>
</table>
<!--</table>-->
</xsl:template>
<xsl:template match="toc-title/text()" mode="x">
<xsl:analyze-string select="substring-after(.,'.')" regex="(\w)">
<xsl:matching-substring>
<xsl:apply-templates select="regex-group(1)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
here what i'm trying to achieve is in my XML in toc-title, there is a number followed by content-style, here my output is having 2 <td>
the number before .
Content after .
if there is no other tag except text after ., i'm able to get the text correctly, and i want to apply-templates for the content after ., please let me know how i can get this done.
here is the demo
Thanks
Related
I've the below XML.
<section level="sect1">
<title num="1.3"><content-style font-style="bold">Common Breaches</content-style></title>
<page num="9"/>
<section level="sect2">
<title><content-style font-style="bolditalic">Non-payment of Rent/Service Charge/Hiring Charge/Licence Fee</content-style></title>
<orderedlist type="manual">
<item num="1.3.1"><para>The most common breach in a Tenancy Agreement is the late payment or non payment of rent. The Tenancy Agreement usually provides for the right of the Landlord to re-enter the premises and determine the tenancy upon non-payment of rent for a period of time. This is in addition to the Landlord's rights to sue the Tenant for any outstanding rent and any monies owing under the tenancy up to the expiry of the tenancy and forfeit the security deposit.</para></item>
<item num="1.3.2"><para>The Landlord may commence what are known as Writ of Distress proceedings or Writ of Summons proceedings to claim for the unpaid rent. The Writ of Distress is the more effective remedy, however only rent may be recovered under the Writ of Distress.</para></item>
</orderedlist>
</section>
and i'm using the below XSLT.
<xsl:template name="section" match="section">
<!-- Variables-->
<xsl:variable name="classname">
<!--Get name attribute of current node -->
<xsl:value-of select="concat('section-',#level)"/>
</xsl:variable>
<xsl:variable name="size">
<xsl:value-of select="string-length(ancestor::chapter[1]/#num)"/>
</xsl:variable>
<xsl:variable name="Chn">
<xsl:value-of select="ancestor::chapter[1]/#num"/>
</xsl:variable>
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:choose>
<xsl:when test="$size=1">
<xsl:value-of select="concat('0',$Chn)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Chn"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sectnum">
<xsl:number level="any" count="section" format="1"/>
</xsl:variable>
<!--Create a string variable by concat string method -->
<xsl:variable name="sectionname">
<xsl:value-of select="concat('CH_',$chapternumber,'-SEC-', $sectnum)"/>
</xsl:variable>
<!-- Template Content -->
<xsl:if test="./page[1]">
<xsl:apply-templates select="./page[1]"/>
</xsl:if>
<div class="{$classname}">
<a name="{$sectionname}"> </a>
<div class="section-title">
<xsl:if test="not(contains(./#num,'unnumbered'))">
<xsl:if test="./title/#num">
<span class="section-num">
<a name="{concat('P',translate(./title/#num,'.','-'))}"></a>
<xsl:value-of select="./title/#num"/>
</span>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:if>
<xsl:apply-templates select="./title/child::node()[fn:not(self::page)]"/>
</div>
<!--<xsl:apply-templates select="child::node()[not(self::title)]"/>-->
</div>
</xsl:template>
<xsl:template name="para" match="section/para">
<xsl:choose>
<xsl:when test="current()/#align">
<div class="para align-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#num">
<xsl:choose>
<xsl:when test="child::node()[1][self::*]">
<xsl:apply-templates select="child::page[1]"/>
<div class="para">
<xsl:call-template name="phrase"/>
<xsl:apply-templates select="child::node()[not(self::page)]"/>
</div>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:call-template name="phrase"/>
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="(([Cc]hapter)\s(\d+))">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="number(regex-group(3)) < number(9)">
<a href="{concat('er:#MCCL_CH_',format-number(number(regex-group(3)),'00'),'/','MCCL_CH_',format-number(number(regex-group(3)),'00'))}">
<xsl:value-of select="."/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="[Pp]aragraphs\s([0-9]+)\.([0-9]+)\sand\s([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="number(regex-group(1)) < number(9)">
<a
href="{concat('er:#MCCL_CH_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
<xsl:value-of select="substring-before(., ' and')"/>
</a>
<xsl:text> and </xsl:text>
<a
href="{concat('er:#MCCL_CH_',format-number(number(regex-group(3)),'00'),'/P',format-number(number(regex-group(3)),'0'),'-',format-number(number(regex-group(4)),'000'))}">
<xsl:value-of select="substring-after(., 'and ')"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="[Pp]aragraph\s([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="number(regex-group(1)) < number(9)">
<a
href="{concat('er:#MCCL_CH_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
<xsl:value-of select="."></xsl:value-of>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="http://[^ ]+">
<xsl:matching-substring>
<a href="{.}">
<xsl:value-of select="."/>
</a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template name="orderedlist" match="orderedlist">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template name="orderitem" match="item">
<xsl:choose>
<xsl:when test="not(ends-with(#num, '.')) and fn:contains(#num,'.')">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<li class="item">
<xsl:apply-templates/>
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="orderitempara" match="item/para">
<xsl:choose>
<xsl:when test="contains(../../#type,'manual')">
<div class="para">
<xsl:choose>
<xsl:when test="position()=1">
<xsl:choose>
<xsl:when test="contains(parent::item[1]/#num,'bull')">
<xsl:text>•</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="not(ends-with(../#num, '.')) and fn:contains(../#num,'.')">
<xsl:call-template name="phrase"/>
</xsl:when>
<xsl:when test="../#num">
<span class="item-num">
<xsl:apply-templates select="parent::item[1]/#num"/>
</span>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:when>
<xsl:otherwise>
<span class="bullet-list">
<xsl:value-of select="../../#type"/>
</span>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="page">
<xsl:processing-instruction name="pb">
<xsl:text>label='</xsl:text>
<xsl:value-of select="./#num"/>
<xsl:text>'</xsl:text>
<xsl:text>?</xsl:text>
</xsl:processing-instruction>
<a name="{concat('pg_',./#num)}"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="phrase">
<xsl:choose>
<xsl:when test="parent::title">
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',#num)"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name">
<xsl:value-of select="$newphrase">
</xsl:value-of>
</xsl:attribute>
</a>
<span class="phrase1">
<xsl:value-of select="current()"/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',../#num)"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name">
<xsl:value-of select="$newphrase">
</xsl:value-of>
</xsl:attribute>
</a>
<span class="phrase">
<xsl:value-of select="../#num"/>
</span>
</xsl:otherwise>
</xsl:choose>
<!--<xsl:apply-templates/>-->
</xsl:template>
when i run this i'm getting output as below.
here the processing instruction number 9 (pb label='9') is getting duplicated, please let me know how can i get the below output.
Thanks
have your page template in a different mode
<xsl:apply-templates select="page[1]" mode="insert_page"/>
and
<xsl:template match="page" mode="insert_page">
<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]">
I've the below piece of XML.
<section level="sect2" number-type="manual">
<para align="center">
<phrase>24-2</phrase>
<content-style font-style="italic">Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong.</content-style>
</para>
</section>
and when i apply the below XSLT
<xsl:template name="para" match="section/para">
<xsl:choose>
<xsl:when test="current()/#align=center and ./#differentiation">
<div class="para align-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#align=center and not(./#differentiation)">
<div class="para align1-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#align and ./phrase[1]">
<div class="para new">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="current()/#align">
<div class="para align-{#align}">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="(([Cc]hapter)\s(\d+))">
<xsl:matching-substring>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<xsl:variable name="num">
<xsl:value-of select="string-length(regex-group(2))"/>
</xsl:variable>
<a
href="{concat('er:#ABHK_CH_',format-number(number(regex-group(2)),'00'),'/P',format-number(number(regex-group(2)),'0'),'-',regex-group(3))}">
<xsl:value-of select="."/>
</a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template name="phrase" match="phrase">
<xsl:variable name="phrl">
<xsl:value-of select="string-length(text())"/>
</xsl:variable>
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',text())"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name">
<xsl:value-of select="$newphrase">
</xsl:value-of>
</xsl:attribute>
</a>
<xsl:choose>
<xsl:when test="../#align">
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
<span class="align-center">
<xsl:apply-templates select="following-sibling::node()[1]"/>
</span>
</xsl:when>
<xsl:when test="$phrl=3">
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
<xsl:text disable-output-escaping="yes">        </xsl:text>
</xsl:when>
<xsl:when test="$phrl=4">
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
<xsl:text disable-output-escaping="yes">    </xsl:text>
</xsl:when>
<xsl:otherwise>
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="content-style">
<xsl:choose>
<xsl:when test="./#format">
<span class="{concat('format-',#format)}">
<xsl:apply-templates/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',#font-style)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:choose>
<xsl:when test="../#align">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
<xsl:apply-templates select="para"/>
</xsl:otherwise>
</xsl:choose>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
the output i get is
24-2 Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong. Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong.
here Destroying [or Damaging] property, contrary to section 60(1) of the Crimes Ordinance Cap 200, Laws of Hong Kong.
is getting repeated though the template is called once. please let me know where am i going wrong.
Thanks
Within the template that matches the para element you are doing this
<xsl:apply-templates/>
This will look at both the child nodes of the para element and select templates that match them. As one of the child elements is content-style this will obviously apply the template that matches it.
However, within the template that matches phrase (which is the other child of para you do this (in the case where the para element has an align attribute, which is does here)
<xsl:apply-templates select="following-sibling::node()[1]"/>
The following sibling is the content-style, and so this will also use the template. Thus the template matching content-style gets called twice.
One solution is to the template matching para so that instead of doing <xsl:apply-templates/>, it explicitly ignores nodes that following phrase elements
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
Try this template for para instead
<xsl:template name="para" match="section/para">
<xsl:choose>
<xsl:when test="current()/#align=center and ./#differentiation">
<div class="para align-{#align}">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:when test="current()/#align=center and not(./#differentiation)">
<div class="para align1-{#align}">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:when test="current()/#align and ./phrase[1]">
<div class="para new">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:when test="current()/#align">
<div class="para align-{#align}">
<xsl:apply-templates select="*[not(preceding-sibling::*[1][local-name()='phrase'])]" />
</div>
</xsl:when>
<xsl:otherwise>
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I have the following template that will display a label, and then the value(s) following it.
<xsl:template match="*" mode="row">
<xsl:param name="title"/>
<tr>
<td width="180">
<xsl:value-of select="$title"/>: </td>
<td>
<xsl:choose>
<xsl:when test="./*">
<xsl:for-each select="./*">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
Called in the following instances:
<xsl:apply-templates select="Details/Detail/DateOfBirth" mode="row">
<xsl:with-param name="title">Date of birth</xsl:with-param>
</xsl:apply-templates>
<xsl:apply-templates select="Addresses" mode="row">
<xsl:with-param name="title">Address(s)</xsl:with-param>
</xsl:apply-templates>
Now - I don't want to have specify the label name each time I apply the template, that should be able to be determined by the node name.
So I create templates for each node to be applied:
<xsl:template match="DateOfBirth">
<xsl:apply-templates select="." mode="row">
<xsl:with-param name="title">Date Of Birth</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Addresses">
<xsl:apply-templates select="." mode="row">
<xsl:with-param name="title">Address(s)</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
And call these with:
<xsl:apply-templates select="Details/Detail/DateOfBirth" mode="row">
</xsl:apply-templates>
<xsl:apply-templates select="Addresses" mode="row">
</xsl:apply-templates>
But it is applying the wildcard template, leaving the label empty. Is there a way to tell it to prefer the explicit template?
I think the reason it preferred the wildcard template is that you were applying templates with mode="row", and your new template rules were in the unnamed mode.
I would do this by creating another mode, with very simple template rules:
<xsl:template match="DateOfBirth" mode="label">Date of Birth</xsl:template>
<xsl:template match="Addresses" mode="label">Address(es)</xsl:template>
and then instead of passing the parameter, you mode="row" template can do
<td width="180">
<xsl:apply-templates select="." mode="label"/>
</td>
Incidentally your xsl:choose also seems amenable to templatization:
<xsl:template match="*[*]" mode="row">
<tr>
<td width="180">
<xsl:apply-templates select="." mode="label"/>
</td>
<td>
<xsl:apply-templates select="*"/>
</td>
</tr>
</xsl:template>
<xsl:template match="*[not(*)]" mode="row">
<tr>
<td width="180">
<xsl:apply-templates select="." mode="label"/>
</td>
<td>
<xsl:apply-templates select="."/>
</td>
</tr>
</xsl:template>
Here's the hack I did:
<xsl:template match="*" mode="row">
<xsl:param name="title"/>
<xsl:choose>
<xsl:when test="$title=''">
<xsl:apply-templates select="."/>
</xsl:when>
<xsl:otherwise>
<tr>
<td width="180">
<xsl:value-of select="$title"/>: </td>
<td>
<xsl:choose>
<xsl:when test="./*">
<xsl:for-each select="./*">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
It checks if the title is blank, if it is (you're calling it for the first time), then it goes off and finds the explicit template for that node, which then re-calls it with the title.
I have met a problem at my work, I am currently developing on an already built website (that i havn't developed myself), and I'm not really familiar with Umbraco and xslt..
This is the code im working on:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<style>
span.cc { font-size:9px;border:1px solid #000;margin-right:3px; }
</style>
<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<table width="100%">
<xsl:variable name="loc" select="umbraco.library:GetXmlDocument('/media/31087/data.xml', 1)"/>
<xsl:for-each select="$loc/rdsppGenData/generatorData">
<xsl:variable name="tags">
<xsl:if test="(OA23) and (not(OA23 = '-'))">cat_1223 </xsl:if>
<xsl:if test="(OA30) and (not(OA30 = '-'))">cat_1868 </xsl:if>
<xsl:if test="(OA36) and (not(OA36 = '-'))">cat_1227 </xsl:if>
<xsl:if test="(OA60) and (not(OA60 = '-'))">cat_1881 </xsl:if>
<xsl:if test="(F0) and (F0 = 'Z01')">cat_1229 </xsl:if>
<xsl:if test="(F0) and (F0 = 'X01')">cat_1802 </xsl:if>
</xsl:variable>
<xsl:variable name="system">
<xsl:choose>
<xsl:when test="F0">
<xsl:value-of select="F1"/>
</xsl:when>
<xsl:when test="(OA23) or (OA30) or (OA36) or (OA60)">
<xsl:value-of select="system"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="TE">
<xsl:choose>
<xsl:when test="F0">
<xsl:value-of select="F2"/>
</xsl:when>
<xsl:when test="(OA23) or (OA30) or (OA36) or (OA60)">
<xsl:value-of select="TE"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="P1">
<xsl:choose>
<xsl:when test="F0">
<xsl:value-of select="P1s"/>
</xsl:when>
<xsl:when test="(OA23) or (OA30) or (OA36) or (OA60)">
<xsl:value-of select="P1"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="P2">
<xsl:choose>
<xsl:when test="F0">
<xsl:value-of select="P2s"/>
</xsl:when>
<xsl:when test="(OA23) or (OA30) or (OA36) or (OA60)">
<xsl:value-of select="P2"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="description">
<xsl:choose>
<xsl:when test="F0">
<xsl:value-of select="Sdescription"/>
</xsl:when>
<xsl:when test="(OA23) or (OA30) or (OA36) or (OA60)">
<xsl:value-of select="description"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:if test="not(contains($system,'_'))">
<xsl:if test="3 = string-length($system)">
<tr class="sys ovs_{generate-id(msxml:node-set($system))} {$tags}" id="sys_{generate-id(msxml:node-set($system))}" >
<td onclick="sys('{generate-id(msxml:node-set($system))}',1)" class="label">
<xsl:value-of select="$system"/>
</td>
<xsl:variable name="systemname" select="translate($system,$ucletters,$lcletters)" />
<td onclick="sys('{generate-id(msxml:node-set($system))}',1)" class="color">
<xsl:if test="(OA23) and (not(OA23 = '-'))">
<span class="cc" style="width:8px;background-color:#4DAA5B;"> </span>
</xsl:if>
<xsl:if test="(OA30) and (not(OA30 = '-'))">
<span class="cc" style="width:8px;background-color:#EDEA87;"> </span>
</xsl:if>
<xsl:if test="(OA36) and (not(OA36 = '-'))">
<span class="cc" style="width:8px;background-color:#EA6A00;"> </span>
</xsl:if>
<xsl:if test="(OA60) and (not(OA60 = '-'))">
<span class="cc" style="width:8px;background-color:#C897CC;"> </span>
</xsl:if>
<xsl:if test="(F0) and (F0 = 'Z01')">
<span class="cc" style="width:8px;background-color:#829ED8;"> </span>
</xsl:if>
<xsl:if test="(F0) and (F0 = 'X01')">
<span class="cc" style="width:8px;background-color:#9FAD00;"> </span>
</xsl:if>
</td>
<td onclick="sys('{generate-id(msxml:node-set($system))}',1)" class="kw">
<span class="keyword"><xsl:value-of select="$description"/> </span>
</td>
</tr>
</xsl:if>
<xsl:if test="5 = string-length($system)">
<xsl:if test="(3 > string-length($TE)) or (not($TE))">
<xsl:variable name="tags2">
<xsl:if test="(OA23) and (not(OA23 = '-'))">cat_1223 </xsl:if>
<xsl:if test="(OA30) and (not(OA30 = '-'))">cat_1868 </xsl:if>
<xsl:if test="(OA36) and (not(OA36 = '-'))">cat_1227 </xsl:if>
<xsl:if test="(OA60) and (not(OA60 = '-'))">cat_1881 </xsl:if>
<xsl:if test="(F0) and (F0 = 'Z01')">cat_1229 </xsl:if>
<xsl:if test="(F0) and (F0 = 'X01')">cat_1802 </xsl:if>
</xsl:variable>
<xsl:variable name="second_level_id" select="generate-id(msxml:node-set($system))" />
<tr id="sys_{generate-id(msxml:node-set($system))}" style="display:none" class="sys2 {generate-id(msxml:node-set($system))} {$tags2}">
<td style="padding-left:30px; width:190px;" onclick="sys('{generate-id(msxml:node-set($system))}',2)" class="label">
<xsl:value-of select="$system"/>
</td>
<td class="gallery_icon">
</td>
<td onclick="sys('{generate-id(msxml:node-set($system))}',2)"> </td>
<td class="keyword" onclick="sys('{generate-id(msxml:node-set($system))}',2)">
<xsl:value-of select="$description"/>
</td>
</tr>
</xsl:if>
</xsl:if>
<xsl:if test="($TE) and (not($TE = '-')) and (not($TE = ''))">
<xsl:variable name="tags3">
<xsl:if test="(OA23) and (not(OA23 = '-'))">cat_1223 </xsl:if>
<xsl:if test="(OA30) and (not(OA30 = '-'))">cat_1868 </xsl:if>
<xsl:if test="(OA36) and (not(OA36 = '-'))">cat_1227 </xsl:if>
<xsl:if test="(OA60) and (not(OA60 = '-'))">cat_1881 </xsl:if>
<xsl:if test="(F0) and (F0 = 'Z01')">cat_1229 </xsl:if>
<xsl:if test="(F0) and (F0 = 'X01')">cat_1802 </xsl:if>
</xsl:variable>
<xsl:variable name="third_level_id" select="generate-id(msxml:node-set($TE))" />
<tr id="sys_{generate-id(msxml:node-set($TE))}" style="display:none" class="sys3 sub_{second_level_id} {generate-id(msxml:node-set($TE))} {$tags3}">
<td style="padding-left:60px; width:160px;" onclick="sys('{generate-id(msxml:node-set($TE))}',3)" class="label">
<xsl:value-of select="$TE"/>
</td>
<td class="gallery_icon">
</td>
<td onclick="sys('{generate-id(msxml:node-set($TE))}',3)"> </td>
<td class="keyword" onclick="sys('{generate-id(msxml:node-set($TE))}',3)">
<xsl:value-of select="$description"/>
</td>
</tr>
</xsl:if>
<xsl:if test="($P1) and (not($P1 = '-')) and (not($P1 = ''))">
<xsl:variable name="tags4">
<xsl:if test="(OA23) and (not(OA23 = '-'))">cat_1223 </xsl:if>
<xsl:if test="(OA30) and (not(OA30 = '-'))">cat_1868 </xsl:if>
<xsl:if test="(OA36) and (not(OA36 = '-'))">cat_1227 </xsl:if>
<xsl:if test="(OA60) and (not(OA60 = '-'))">cat_1881 </xsl:if>
<xsl:if test="(F0) and (F0 = 'Z01')">cat_1229 </xsl:if>
<xsl:if test="(F0) and (F0 = 'X01')">cat_1802 </xsl:if>
</xsl:variable>
<xsl:variable name="fourth_level_id" select="generate-id(msxml:node-set($P1))" />
<tr id="sys_{generate-id(msxml:node-set($P1))}" style="display:none" class="sys4 sub_{third_level_id} subi_{second_level_id} {generate-id(msxml:node-set($P1))} {$tags4}">
<td style="padding-left:90px; width:130px;" onclick="sys('{generate-id(msxml:node-set($P1))}',4)" class="label">
<xsl:value-of select="$P1"/>
</td>
<td class="gallery_icon">
</td>
<td onclick="sys('{generate-id(msxml:node-set($P1))}',4)"> </td>
<td class="keyword" onclick="sys('{generate-id(msxml:node-set($P1))}',4)">
<xsl:value-of select="$description"/>
</td>
</tr>
</xsl:if>
<xsl:if test="($P2) and (not($P2 = '-')) and (not($P2 = ''))">
<xsl:variable name="tags5">
<xsl:if test="(OA23) and (not(OA23 = '-'))">cat_1223 </xsl:if>
<xsl:if test="(OA30) and (not(OA30 = '-'))">cat_1868 </xsl:if>
<xsl:if test="(OA36) and (not(OA36 = '-'))">cat_1227 </xsl:if>
<xsl:if test="(OA60) and (not(OA60 = '-'))">cat_1881 </xsl:if>
<xsl:if test="(F0) and (F0 = 'Z01')">cat_1229 </xsl:if>
<xsl:if test="(F0) and (F0 = 'X01')">cat_1802 </xsl:if>
</xsl:variable>
<tr id="sys_{generate-id(msxml:node-set($P2))}" style="display:none" class="sys5 subi_{third_level_id} subi_{second_level_id} sub_{fourth_level_id} {generate-id(msxml:node-set($P2))} {$tags5}">
<td style="padding-left:120px; width:100px;" onclick="sys('{generate-id(msxml:node-set($P2))}',5)" class="label">
<xsl:value-of select="$P2"/>
</td>
<td class="gallery_icon">
</td>
<td onclick="sys('{generate-id(msxml:node-set($P2))}',5)"> </td>
<td class="keyword" onclick="sys('{generate-id(msxml:node-set($P2))}',5)">
<xsl:value-of select="$description"/>
</td>
</tr>
</xsl:if>
</xsl:if>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
And i am trying to get the unique ID from the prev. tr and use it in the current row..
I want to use the variable:
<xsl:variable name="second_level_id" select="generate-id(msxml:node-set($system))" />
in this line:
<tr id="sys_{generate-id(msxml:node-set($TE))}" style="display:none" class="sys3 sub_{second_level_id} {generate-id(msxml:node-set($TE))} {$tags3}">
And so on.
If there is ANY better way of doing all of this, where i would get the exact same output, but with the desired variable thingy from above, i would love to hear about it.
Mathias
Here is a way you should be able to accomplish this:
Replace this:
<xsl:for-each select="$loc/rdsppGenData/generatorData">
with:
<xsl:variable name="locItems" select="$loc/rdsppGenData/generatorData" />
<xsl:apply-templates select="$locItems[1]">
<xsl:with-param name="remainder" select="$locItems[position() > 1" />
</xsl:apply-templates>
Add this to your XSLT:
<xsl:template match="generatorData">
<xsl:param name="remainder" />
<xsl:param name="last_second_level_id" />
<xsl:param name="last_third_level_id" />
<!-- Move the contents of the xsl:for-each in here -->
<xsl:apply-templates select="$remainder[1]">
<xsl:with-param name="remainder" select="$remainder[position() > 1]" />
<xsl:with-param name="last_second_level_id" select="$second_level_id" />
<xsl:with-param name="last_thirdlevel_id" select="$second_level_id" />
</xsl:apply-templates>
</xsl:template>