for loop skipping the content and showing further data - xslt

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.

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>

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.

text is getting repeated though the template is unique

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">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</xsl:text>
</xsl:when>
<xsl:when test="$phrl=4">
<span class="phrase">
<xsl:value-of select="current()"/>
</span>
<xsl:text disable-output-escaping="yes">&#160;&#160;&#160;&#160;</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>

insert div after X li

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>

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.