insert div after X li - xslt

I have an xslt navigation, which I want to break into 2 columns, so that after every 6 "li" it creates a new "div"...
I would like to output to be like this:
<ul>
<div class="col">
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
</div>
<div class="col">
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
</div>
</ul>
But not quite sure how to do this
My XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
<xsl:param name="html-content-type" />
<xsl:template match="/NavigationTree">
<xsl:if test="count(//Page) > 0">
<ul>
<xsl:apply-templates select="Page">
<xsl:with-param name="depth" select="1"/>
</xsl:apply-templates>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="//Page">
<xsl:param name="depth"/>
<li>
<xsl:attribute name="class">
<xsl:if test="#InPath='True'">inpath </xsl:if>
<xsl:if test="position() = 1">firstitem </xsl:if>
<xsl:if test="position() = count(//Page)">lastitem </xsl:if>
<xsl:if test="#Active='True'">selected</xsl:if>
</xsl:attribute>
<a>
<xsl:attribute name="class">
<xsl:if test="#InPath='True'">inpath </xsl:if>
<xsl:if test="position() = 1">firstitem </xsl:if>
<xsl:if test="position() = count(//Page)">lastitem </xsl:if>
<xsl:if test="#Active='True'">current</xsl:if>
</xsl:attribute>
<xsl:attribute name="href"><xsl:value-of select="#FriendlyHref" disable-output-escaping="yes"/></xsl:attribute>
<xsl:value-of select="#MenuText" disable-output-escaping="yes"/>
</a>
<div class="icon">
<xsl:text disable-output-escaping="yes"><![CDATA[<!--dsfdsfdsf-->]]></xsl:text>
</div>
<xsl:if test="count(Page)">
<ul class="M{#AbsoluteLevel}">
<xsl:apply-templates select="Page">
<xsl:with-param name="depth" select="$depth+1"/>
</xsl:apply-templates>
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>

A way to do it would be to have a template that matches every 6 Page element:
<xsl:template match="//Page[position() mod 6 = 1]">
<div>
<xsl:apply-templates select="." mode="SecondLevel"/>
<xsl:apply-templates select="following-sibling::Page[position()<6]" mode="SecondLevel"/>
</div>
</xsl:template>
generating the div and applying a second-level template to the current element and its 5 following sibling. The second level template is the one you already have - with an added mode:
<xsl:template match="Page" mode="SecondLevel">
<li>
<xsl:attribute name="class">
<xsl:if test="#InPath='True'">inpath </xsl:if>
<xsl:if test="position() = 1">firstitem </xsl:if>
<xsl:if test="position() = count(//Page)">lastitem </xsl:if>
<xsl:if test="#Active='True'">selected</xsl:if>
</xsl:attribute>
<a>
<xsl:attribute name="class">
<xsl:if test="#InPath='True'">inpath </xsl:if>
<xsl:if test="position() = 1">firstitem </xsl:if>
<xsl:if test="position() = count(//Page)">lastitem </xsl:if>
<xsl:if test="#Active='True'">current</xsl:if>
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="#FriendlyHref" disable-output-escaping="yes"/>
</xsl:attribute>
<xsl:value-of select="#MenuText" disable-output-escaping="yes"/>
</a>
<div class="icon">
<xsl:text disable-output-escaping="yes"><![CDATA[<!--dsfdsfdsf-->]]></xsl:text>
</div>
</li>
</xsl:template>

Related

convert xml to html list with xslt

I have a xslt code to convert an xml file to html list. The input and output samples are as follows:
Input:
<Beverages>
<Water/>
<Coffee/>
<Tea>
<BlackTea/>
<WhiteTea id="cti" value="ctv" >Camomile Tea</WhiteTea>
<GreenTea id="gti" value="gtv">
<Sencha/>
<Gyokuro/>
<Matcha/>
<PiLoChun/>
</GreenTea>
</Tea>
</Beverages>
and the Output:
<ul>
<li>
<span class="caret"><Beverages></span>
<ul class="nested">
<li><span><Water/></span></li>
<li><span><Coffee/></span></li>
<li>
<span class="caret"><Tea></span>
<ul class="nested">
<li><span><BlackTea/></span></li>
<li><span><WhiteTea id="cti" value="ctv"></span>Camomile Tea<span></WhiteTea></span></li>
<li>
<span><GreenTea id="gti" value="gtv"></span>
<ul class="nested">
<li><span><Sencha/></span></li>
<li><span><Gyokuro/></span></li>
<li><span><Matcha/></span></li>
<li><span><PiLoChun/></span></li>
</ul>
<span></GreenTea></span>
</li>
</ul>
</li>
</ul>
<span></Beverages></span>
</li>
</ul>
Here is my xslt but it is not exactly the same as what I want:
<xsl:template match="/">
<ul><xsl:apply-templates/></ul>
</xsl:template>
<xsl:template match="*">
<li> <span class="caret"><xsl:value-of select="concat('<',name())" />
<xsl:for-each select="#*">
<xsl:value-of select="concat(' ',name())"/>=<xsl:value-of select="concat('"',.,'"')" />
</xsl:for-each>></span>
<xsl:if test="text()">
<xsl:apply-templates select="text()" />
</xsl:if>
<xsl:if test="*">
<ul class="nested"><xsl:apply-templates/></ul>
</xsl:if>
<span><xsl:value-of select="concat('<','/' ,name() , '>')" /></span></li>
</xsl:template>
The problem is that this code can not differentiate between parent elements and non parent element. for parent elements we need to add class="caret" attribute, but for non parent elements we shouldn't add this class.
This should work for you.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="*">
<li>
<span>
<xsl:if test="*">
<xsl:attribute name="class">
<xsl:value-of select="'caret'"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="concat('<',name())"/>
<xsl:for-each select="#*">
<xsl:value-of select="concat(' ', name(), '=', '"', ., '"')"/>
</xsl:for-each>
<xsl:choose>
<xsl:when test="text() or *">
<xsl:value-of select="'>'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'\>'"/>
</xsl:otherwise>
</xsl:choose>
</span>
<xsl:if test="text()">
<xsl:value-of select="text()"/>
</xsl:if>
<xsl:if test="*">
<ul class="nested">
<xsl:apply-templates/>
</ul>
</xsl:if>
<xsl:if test="text() or *">
<span>
<xsl:value-of select="concat('<','/' ,name() , '>')"/>
</span>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>

XSLT list item position issue

pls check the below code. I am matching the list element and as per the below code the position() function returns correct number of the element with in ul elements i.e 1,2,3 where as if i do the test with position i get only ss,ss,ss . Can anyone let me know where am missing ?
XSL-FO
<xsl:template match="html:li" priority="2">
<fo:list-item>
...
<xsl:value-of select="position()"/> -- this returns 1,2,3
<xsl:if test="position() = 1">
<xsl:text>ss</xsl:text> -- only executes
</xsl:if>
<xsl:if test="position() = 2">
<xsl:text>ssddddd</xsl:text> -- does not only execute
</xsl:if>
<xsl:if test="position() = 3">
<xsl:text>sskkkkkkkkk</xsl:text> -- does not only execute
</xsl:if>
</fo:list-item>
</xsl:template
XSL
<xsl:template match="list">
<xsl:if test="list.item">
<xsl:variable name="styleAttr">
<xsl:text>margin-top: 1em;</xsl:text>
</xsl:variable>
<div>
<xsl:if test="string-length($styleAttr) > 0">
<xsl:attribute name="style">
<xsl:value-of select="$styleAttr"/>
</xsl:attribute>
</xsl:if>
<ul>
<xsl:apply-templates select="node()[not(self::list)]" />
</ul>
</div>
</xsl:if>
</xsl:template>
<xsl:template match="list.item" priority="1">
<li style="padding: 0;">
<div style="margin-bottom: 0.5em;">
<xsl:apply-templates />
<xsl:if test="following-sibling::node()[1][self::list]">
<xsl:apply-templates select="following-sibling::node()[1]" />
</xsl:if>
</div>
</li>
</xsl:template>

Template match not entered

I've the below code in XML.
<?xml version="1.0" encoding="UTF-8"?>
<toa>
<title>TABLE OF HONG KONG LEGISLATION</title>
<subtitle>All references are to paragraph number</subtitle>
<toa-section>
<toa-div level="div1">
<title/>
<toa-entry>
<primary-entry>
<entry-name>Banking Ordinance (Cap.155)</entry-name>
<pgs>7.040</pgs>
</primary-entry>
</toa-entry>
</toa-div>
</toa-section>
</toa>
and the XSLT is as below.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><!DOCTYPE html>
</xsl:text>
<html>
<head>
<xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
<title>TABLE OF LEGISLATION</title>
<link rel="stylesheet" href="C:\Users\u0138039\Desktop\In Progress\Company Law-Insolvency 2014 Edition_xml\XSLT\main.css" type="text/css" /><xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
</head>
<body>
<section class="tr_toa">
<xsl:call-template name="toa"></xsl:call-template>
</section>
</body>
</html>
</xsl:template>
<xsl:template name="toa">
<div class="toa">
<a name="CLI_TOL_01"> </a>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="toa/title">
<div class="toa-title">
<xsl:value-of select="current()/content-style/text()"/>
</div>
</xsl:template>
<xsl:template match="toa-section">
<div class="toa-section">
<xsl:for-each select="current()/toa-div">
<xsl:call-template name="toa-div" />
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="toa-div" name="toa-div">
<xsl:variable name="divClass" select="concat('toa-div level-', current()/#level)"></xsl:variable>
<div class="{$divClass}">
<div class="toa-div-title">
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',title/content-style/#font-style)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:value-of select="current()/title/content-style/text()"/>
</span>
</div>
<xsl:apply-templates select="toa-entry" />
</div>
</xsl:template>
<xsl:template match="toa-entry">
<xsl:choose>
<xsl:when test="not(preceding-sibling::toa-entry[1]/primary-entry/secondary-entry/node()) and position() != 1">
</xsl:when>
<xsl:otherwise>
<table class="toa-entry">
<tbody>
<xsl:apply-templates select="primary-entry" />
<xsl:if test="not(current()/primary-entry/secondary-entry/node())">
<xsl:apply-templates select="following-sibling::toa-entry[1]" mode="next"/>
</xsl:if>
</tbody>
</table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="toa-entry" mode="next">
<xsl:apply-templates select="primary-entry"/>
<xsl:if test="not(current()/primary-entry/secondary-entry/node())">
<xsl:apply-templates select="following-sibling::toa-entry[1]" mode="next"/>
</xsl:if>
</xsl:template>
<xsl:template match="primary-entry">
<tr class="primary-entry">
<td class="entry-name">
<xsl:value-of select="current()/entry-name/text()"/>
</td>
<xsl:if test="current()/pgs/node()">
<td class="pgs" >
<xsl:variable name="pgcount" select="count(current()/pgs)"/>
<xsl:for-each select="current()/pgs">
<xsl:apply-templates select="./pgs"></xsl:apply-templates>
</xsl:for-each>
</td>
</xsl:if>
</tr>
<xsl:if test="current()/secondary-entry/node()">
<xsl:for-each select="current()/secondary-entry">
<tr class="secondary-entry">
<td class="entry-name">
<xsl:value-of select="current()/entry-name/text()"/>
</td>
<xsl:if test="current()/pgs/node()">
<td class="pgs" >
<xsl:variable name="pgcount" select="count(current()/pgs)"/>
<xsl:for-each select="current()/pgs">
<xsl:apply-templates></xsl:apply-templates>
</xsl:for-each>
</td>
</xsl:if>
</tr>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template match="pgs">
<td class="pgs">
<xsl:analyze-string select="." regex="[^,\s]+">
<xsl:matching-substring>
<xsl:variable name="range" select="tokenize(.,'—')"/>
<xsl:variable name="pg" select="tokenize(.,'/')"/>
<xsl:choose>
<xsl:when test="contains($pg[3],'—')">
<xsl:variable name="range-pg" as="item()*">
<xsl:for-each select="$range">
<xsl:sequence select="tokenize(.,'/')"/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="xs:integer($range-pg[3]) to xs:integer($range-pg[6])">
<a href="er:#HKWBV1_ORD_{
if (string(number($range-pg[1]))!='NaN') then
format-number(number($range-pg[1]),'00')
else
$range-pg[1]}/P{string-join($range-pg[position()=(1,2)],'/')}/{.}">
<xsl:value-of select="concat(string-join($range-pg[position()=(1,2)],'/'),'/',.)"/>
</a>
<xsl:text>, </xsl:text>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<a href="er:#HKWBV1_ORD_{
if (string(number($pg[1]))!='NaN') then
format-number(number($pg[1]),'00')
else
$pg[1]}/P{$pg[1]
}/{string-join($pg[position()>1],'/')}">
<xsl:value-of select="."/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</td>
</xsl:template>
</xsl:stylesheet>
though i have written a template match for pgs, while debugging, the flow is not entering the template. Please let me know where am i going wrong.
Thanks
change
<xsl:template match="primary-entry">
<tr class="primary-entry">
<td class="entry-name">
<xsl:value-of select="current()/entry-name/text()"/>
</td>
<xsl:if test="current()/pgs/node()">
<td class="pgs" >
<xsl:variable name="pgcount" select="count(current()/pgs)"/>
<xsl:for-each select="current()/pgs">
<xsl:apply-templates select="./pgs"></xsl:apply-templates>
</xsl:for-each>
</td>
</xsl:if>
to
<xsl:template match="primary-entry">
<tr class="primary-entry">
<td class="entry-name">
<xsl:value-of select="current()/entry-name/text()"/>
</td>
<xsl:if test="current()/pgs/node()">
<xsl:apply-templates select="pgs"/>
</xsl:if>
and do the same for the secondary template.

stackoverflow is occured in using loops in my code

i've the below xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" exclude-result-prefixes="ntw">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
<link rel="stylesheet" href="C:\Documents and Settings\u0138039\Desktop\Per\NEW.css" type="text/css"></link>
</head>
<body>
<section class="tr_chapter">
<div class="chapter">
<xsl:apply-templates/>
</div>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="case">
<xsl:apply-templates select="case.head"/>
</xsl:template>
<xsl:template match="case.head">
<div class="section-sect0">
<div class="para">
<xsl:value-of select="./party.line/party[#role='Plaintiff']"/>
</div>
</div>
<div class="section-sect0">
<div class="para">
<xsl:text disable-output-escaping="yes">V</xsl:text>
</div>
</div>
<div class="section-sect0">
<div class="para">
<xsl:value-of select="./party.line/party[#role='Defendant']"/>
</div>
</div>
<xsl:apply-templates select="case.ref.no.group | judge.line"/>
</xsl:template>
<xsl:template match="para">
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="case.ref.no.group">
<div class="section-sect3">
<span class="font-style-bold">Court of Appeal</span>
<xsl:text> - </xsl:text>
<xsl:value-of select="case.ref.no[1]/prefix" />
<xsl:text> Nos. </xsl:text>
<xsl:for-each select="case.ref.no">
<xsl:value-of select="number" />
<xsl:text>-</xsl:text>
<xsl:value-of select="year" />
<xsl:if test="not(position() = 2)">
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="judge.line">
<div class="section-sect3">
<xsl:for-each select="judge">
<xsl:value-of select="name"/>
<xsl:if test="not(position() = last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> JC</xsl:text>
</div>
<xsl:apply-templates select="following-sibling::date.group"></xsl:apply-templates>
</xsl:template>
<xsl:template match="date.group">
<div class="section-sect4">
<div class="para">
<xsl:value-of select="./date.line/date"/>
</div>
</div>
<xsl:apply-templates select="//catchwords.group"/>
</xsl:template>
<xsl:template match="catchwords.group">
<div class="y">
<xsl:for-each select="catchwords/catchword">
<xsl:choose>
<xsl:when test="#level=1"><br/>
<span class="font-style-bolditalic">
<xsl:value-of select="."/>
</span>
<xsl:text disable-output-escaping="yes">-</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select=".">
<xsl:value-of select="."></xsl:value-of>
<xsl:if test="not(position() = last()-1)">
<xsl:text disable-output-escaping="yes"> – </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
<xsl:apply-templates select="//headnotes"/>
</xsl:template>
<xsl:template match="headnotes/para">
<xsl:choose>
<xsl:when test="position()=1">
<div class="x">
<xsl:apply-templates></xsl:apply-templates>
</div>
</xsl:when>
<xsl:otherwise>
<div class="m">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="para.group"/>
</xsl:template>
<xsl:template match="para.group">
<div class="section-sect1">
<xsl:value-of select="./heading"/>
</div>
<xsl:for-each select="./para">
<xsl:apply-templates select="node()[not(self::label)]"/>
</xsl:for-each>
<xsl:apply-templates select="//counsel.group"/>
</xsl:template>
<xsl:template name="orderedlist" match="list">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates select="list.item/label"/>
</ol>
</xsl:template>
<xsl:template name="orderitempara" match="list.item/label">
<li class="item">
<div class="para">
<span class="item-num">
<xsl:choose>
<xsl:when test="following-sibling::case.considered">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</span>
<xsl:apply-templates select="parent::list.item"/>
</div>
</li>
</xsl:template>
<xsl:template match="list.item">
<xsl:variable name="a">
<xsl:value-of select="./label"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="./label">
<xsl:apply-templates select="child::node()[not(self::label|case.ref)]"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="counsel.group" name="j">
<div class="ital">
<xsl:for-each select="./counsel.line">
<div class="para">
<xsl:value-of select="."/>
</div>
</xsl:for-each>
<xsl:text disable-output-escaping="yes">Judgment received: December 4, 2008</xsl:text>
</div>
<xsl:apply-templates select="//ref.group"/>
</xsl:template>
<xsl:template match="ref.group/leg.mentioned">
<div class="section-sect1">
<xsl:text>Legislation mentioned in the judgment</xsl:text>
</div>
<xsl:for-each select="./leg.ref">
<div class="para">
<xsl:value-of select="./citetitle"/>
<xsl:text>, </xsl:text>
<xsl:for-each select="./leg.ptr.group/leg.ptr">
<xsl:value-of select="."/>
<xsl:if test="not(position() = last())">
<xsl:text disable-output-escaping="yes">, </xsl:text>
</xsl:if>
</xsl:for-each>
</div>
</xsl:for-each>
<xsl:text>Cases cited in the judgment</xsl:text>
<xsl:for-each select="//citetitle">
<xsl:if test="parent::case.ref/#annotation">
<div class="ital">
<div class="para">
<xsl:value-of select="."/>
<xsl:value-of select="//citecitation"/>
<xsl:value-of select="parent::case.ref/#court"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="parent::case.ref/#annotation"/>
<xsl:text>)</xsl:text>
</div>
</div>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates select="//judgment"/>
</xsl:template>
<xsl:template match="judgment">
<div class="section-sect1">
<xsl:value-of select="./judge.block/heading/judgename"/>
</div>
<xsl:for-each select="./judge.block/para">
<div class="para">
<span class="new">
<xsl:value-of select="./label"></xsl:value-of>
</span>
<xsl:value-of select="./text()"/>
</div>
<xsl:apply-templates select="./list"/>
</xsl:for-each>
<xsl:for-each select="./judge.block/para.group">
<xsl:if test="./heading">
<div class="section-sect1">
<xsl:value-of select="./heading/text()"/>
</div>
</xsl:if>
<xsl:for-each select="para">
<div class="para">
<span class="new">
<xsl:value-of select="./label"></xsl:value-of>
</span>
<xsl:apply-templates select="child::node()[not(self::label)]"/>
</div>
<xsl:apply-templates select="./list"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="emphasis">
<xsl:choose>
<xsl:when test="citetitle">
<span class="font-style-italic">
<xsl:apply-templates select="./list.item"/>
</span>
</xsl:when>
<xsl:when test="./#type">
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',#type)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:apply-templates/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
when i apply this on my below part of my xml it is giving me a stackoverflow error.
<?xml version="1.0" encoding="UTF-8"?>
<case>
<counsel.group>
<counsel.line>Azar Irwan b Moh Arifin (AG’s Chambers) for Public Prosecutor</counsel.line>
<counsel.line>SK Pari (Pari & Co) for first accused</counsel.line></counsel.group>
<ref.group>
<leg.mentioned>
<leg.ref country="India">
<citetitle type="leg" legtype="ord">Indian Penal Code</citetitle>
<leg.ptr.group>
<leg.ptr provision="s" print="yes">302</leg.ptr>
</leg.ptr.group>
</leg.ref>
<leg.ref country="Malaysia">
<citetitle type="leg" legtype="ord">Criminal Procedure Code</citetitle>
<leg.ptr.group>
<leg.ptr provision="ss" print="yes">112</leg.ptr>
<leg.ptr provision="s" print="no">112</leg.ptr>
</leg.ptr.group>
</leg.ref>
<leg.ref country="Malaysia">
<citetitle type="leg" legtype="ord">Penal Code</citetitle>
<leg.ptr.group>
<leg.ptr provision="ss" print="yes">109</leg.ptr>
<leg.ptr provision="s" print="no">299</leg.ptr>
</leg.ptr.group>
</leg.ref>
</leg.mentioned></ref.group>
</case>
please let me know how do i resolve this error and what are the steps to be followed so that in future i don't encounter this error.
Thanks
Your XSLT contains an infinite loop. Your para.group template contains this:
<xsl:apply-templates select="//counsel.group"/>
And then the template for counsel.group has this:
<xsl:apply-templates select="//ref.group"/>
The template for ref.group has this:
<xsl:apply-templates select="//judgment"/>
The template for judgment has this:
<xsl:for-each select="para">
...
<xsl:apply-templates select="child::node()[not(self::label)]"/>
...
</xsl:for-each>
Which cascades down to apply templates on a para.group and then you're back at the beginning. This process goes around in circles until the stack overflows. I think you need to rethink your XSLT to figure out how to prevent infinite recursion.

for loop skipping the content and showing further data

i have the below xslt.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" exclude-result-prefixes="ntw">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
<link rel="stylesheet" href="C:\Documents and Settings\u0138039\Desktop\Per\NEW.css" type="text/css"></link>
</head>
<body>
<section class="tr_chapter">
<div class="chapter">
<xsl:apply-templates/>
</div>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="case">
<xsl:apply-templates select="case.head"/>
</xsl:template>
<xsl:template match="case.head">
<div class="section-sect0">
<div class="para">
<xsl:value-of select="./party.line/party[#role='Plaintiff']"/>
</div>
</div>
<div class="section-sect0">
<div class="para">
<xsl:text disable-output-escaping="yes">V</xsl:text>
</div>
</div>
<div class="section-sect0">
<div class="para">
<xsl:value-of select="./party.line/party[#role='Defendant']"/>
</div>
</div>
<xsl:apply-templates select="case.ref.no.group | judge.line"/>
</xsl:template>
<xsl:template match="para">
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="case.ref.no.group">
<div class="section-sect3">
<span class="font-style-bold">Court of Appeal</span>
<xsl:text> - </xsl:text>
<xsl:value-of select="case.ref.no[1]/prefix" />
<xsl:text> Nos. </xsl:text>
<xsl:for-each select="case.ref.no">
<xsl:value-of select="number" />
<xsl:text>-</xsl:text>
<xsl:value-of select="year" />
<xsl:if test="not(position() = 2)">
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="judge.line">
<div class="section-sect3">
<xsl:for-each select="judge">
<xsl:value-of select="name"/>
<xsl:if test="not(position() = last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> JC</xsl:text>
</div>
<xsl:apply-templates select="following-sibling::date.group"></xsl:apply-templates>
</xsl:template>
<xsl:template match="date.group">
<div class="section-sect4">
<div class="para">
<xsl:value-of select="./date.line/date"/>
</div>
</div>
<xsl:apply-templates select="//catchwords.group"/>
</xsl:template>
<xsl:template match="catchwords.group">
<div class="y">
<xsl:for-each select="catchwords/catchword">
<xsl:choose>
<xsl:when test="#level=1"><br/>
<span class="font-style-bolditalic">
<xsl:value-of select="."/>
</span>
<xsl:text disable-output-escaping="yes">-</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select=".">
<xsl:value-of select="."></xsl:value-of>
<xsl:if test="not(position() = last()-1)">
<xsl:text disable-output-escaping="yes"> – </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
<xsl:apply-templates select="//headnotes"/>
</xsl:template>
<xsl:template match="headnotes/para">
<xsl:choose>
<xsl:when test="position()=1">
<div class="x">
<xsl:apply-templates></xsl:apply-templates>
</div>
</xsl:when>
<xsl:otherwise>
<div class="m">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="para.group"/>
</xsl:template>
<xsl:template match="para.group">
<div class="section-sect1">
<xsl:value-of select="./heading"/>
</div>
<xsl:for-each select="./para">
<xsl:apply-templates select="node()[not(self::label)]"/>
</xsl:for-each>
<xsl:apply-templates select="//counsel.group"/>
</xsl:template>
<xsl:template name="orderedlist" match="list">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates select="list.item/label"/>
</ol>
</xsl:template>
<xsl:template name="orderitempara" match="list.item/label">
<li class="item">
<div class="para">
<span class="item-num">
<xsl:choose>
<xsl:when test="following-sibling::case.considered">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</span>
<xsl:apply-templates select="parent::list.item"/>
</div>
</li>
</xsl:template>
<xsl:template match="list.item">
<xsl:variable name="a">
<xsl:value-of select="./label"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="./label">
<xsl:apply-templates select="child::node()[not(self::label|case.ref)]"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="counsel.group" name="j">
<div class="ital">
<xsl:for-each select="./counsel.line">
<div class="para">
<xsl:value-of select="."/>
</div>
</xsl:for-each>
<xsl:text disable-output-escaping="yes">Judgment received: December 4, 2008</xsl:text>
</div>
<xsl:apply-templates select="//ref.group"/>
</xsl:template>
<xsl:template match="ref.group/leg.mentioned">
<div class="section-sect1">
<xsl:text>Legislation mentioned in the judgment</xsl:text>
</div>
<xsl:for-each select="./leg.ref">
<div class="nomar">
<xsl:value-of select="./#country"/>
</div>
<div class="para">
<xsl:value-of select="./citetitle"/>
<xsl:text>, </xsl:text>
<xsl:for-each select="./leg.ptr.group/leg.ptr">
<xsl:value-of select="."/>
<xsl:if test="not(position() = last())">
<xsl:text disable-output-escaping="yes">, </xsl:text>
</xsl:if>
</xsl:for-each>
</div>
</xsl:for-each>
<div class="section-sect1">
<xsl:text>Cases cited in the judgment</xsl:text>
</div>
<xsl:apply-templates select="//case.considered"/>
<div class="section-sec1">
<xsl:apply-templates select="//other.mentioned"/>
</div>
</xsl:template>
<xsl:template match="case.considered">
<xsl:for-each select=".">
<xsl:if test="./case.ref">
<div class="para">
<span class="font-style-italic">
<xsl:value-of select="./case.ref/citetitle[#full]"/></span>
<xsl:text> </xsl:text>
<xsl:value-of select="./case.ref/citecitation/#full"/>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="other.mentioned/other.ref">
<div class="para">
<xsl:value-of select="./author"/>
<xsl:text>, </xsl:text>
<span class="font-style-italic">
<xsl:value-of select="./book.title"/>
</span>
<xsl:text>, </xsl:text>
<xsl:value-of select="ed_vol"/>
<xsl:value-of select="./ref_grp/reference/pageno"/>
</div>
<xsl:apply-templates select="//judgment"/>
</xsl:template>
<xsl:template match="judgment">
<div class="section-sect1">
<xsl:value-of select="./judge.block/heading"/>
</div>
<!--<xsl:for-each select="./judge.block/para.group">
--><!--<div class="para">
<span class="new">
<xsl:value-of select="./label"></xsl:value-of>
</span>
<xsl:value-of select="./text()"/>
</div>
<xsl:apply-templates select="./list"/>--><!--
<xsl:apply-templates/>
</xsl:for-each>-->
<xsl:apply-templates select="./judge.block/para.group"/>
</xsl:template>
<xsl:template match="judge.block/para.group">
<div class="section-sect1">
<xsl:apply-templates select="./heading"/>
</div>
<xsl:for-each select="./para">
<div class="para">
<span class="new">
<xsl:value-of select="./label"/></span>
<xsl:apply-templates select="./text()"/>
</div>
<xsl:if test="./block.quote">
<xsl:for-each select="./block.quote/para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<xsl:for-each select="./para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<div class="extract">
<div class="para">
<xsl:apply-templates select="./para"/>
</div></div>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="./para.group">
<xsl:if test="./para.group">
<xsl:choose>
<xsl:when test="not(./para)">
<div class="ital">
<xsl:apply-templates select="./heading"/>
</div></xsl:when>
<xsl:otherwise>
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<div class="para">
<span class="new">
<xsl:value-of select="./para/label"/>
</span>
<xsl:value-of select="./para/text()"/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
<xsl:if test="./block.quote">
<xsl:for-each select="./block.quote/para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<xsl:for-each select="./para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<div class="extract">
<div class="para">
<div class="new">
<xsl:value-of select="./para/label"/>
</div>
<xsl:apply-templates select="./para/text()"/>
</div></div>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template match="emphasis">
<xsl:choose>
<xsl:when test="citetitle">
<span class="font-style-italic">
<xsl:apply-templates select="./list.item"/>
</span>
</xsl:when>
<xsl:when test="./#type">
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',#type)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:apply-templates/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
and when i use it on my xml, the output is skipping the content in between(for example i am able to see content with number[12] and then it is directly jumping to content in number [16] and the content in between is skipped). the xml can be found in the following link.
XML Doc. please let me know where am i going wrong.
Thanks
It is really hard to tell from the information you gave, but I think your problem comes from the fact that the "para" elements with the "labels" 13-15 actually lie within a nested second para.group element within the first one.
Your template probably only matches "para" elements directly within "para.group" elements, but not nested "para.group" elements.
As an outsider, it's basically impossible to tell without investing way too much time in analyzing the huge input you gave, which is probably why you didn't receive another answer up until now.