I'm writing an xsl script in which I need to create the attribute dynamically.
Here is my sample code.
<Table BORDERLINESTYLE="solid" BOTTOMMARGIN="12" NOTEGROUPSPACING="single" CELLPADDING="0" CELLSPACING="0" WIDTH="504"></Table>
Here BORDERLINESTYLE may or may not be available to all Table tags. and I want the output to be something like this.
<table style="border-style:solid; border-margin:12px; width:504px"></table>
Here are 2 things that I've tried.
1. Creating attributes
<table>
<xsl:if test="./#BORDERLINESTYLE">
<xsl:attribute name="border" select="'1px solid'"/>
</xsl:if>
<xsl:if test="./#WIDTH">
<xsl:attribute name="width" select="concat(./#WIDTH, 'px')"/>
</xsl:if>
<xsl:if test="./#BOTTOMMARGIN">
<xsl:attribute name="border" select="'1px solid'"/>
</xsl:if>
<xsl:apply-templates/>
</table>
the output that I get is as below.
<table border="1px solid" width="504px">
2. Inline adding
<table style="width:{current()/#WIDTH,'px'}; border:{./#BORDERLINESTYLE}; margin-bottom: {./#BOTTOMMARGIN, 'px'}; margin-top:{./#TOPMARGIN, 'px'}; "></table>
and the output is as below with some blank values like margin-top
<table style="width:504 px; border:solid; margin-bottom: 12 px; margin-top:px; ">
How can I add styles to style based on the attributes provided in the XML?
I'm using XSLT2.0.
I would use something like this:
<xsl:if test="#BORDERLINESTYLE|#WIDTH|#BOTTOMMARGIN|#TOPMARGIN">
<xsl:attribute name="style">
<xsl:if test="#BORDERLINESTYLE">
<xsl:text>border:1px solid;</xsl:text>
</xsl:if>
<xsl:if test="#WIDTH">
<xsl:value-of select="concat('width:',#WIDTH, 'px;')"/>
</xsl:if>
<xsl:if test="#BOTTOMMARGIN">
<xsl:value-of select="concat('margin-bottom:',#BOTTOMMARGIN, 'px;')"/>
</xsl:if>
<xsl:if test="#TOPMARGIN">
<xsl:value-of select="concat('margin-top:',#TOPMARGIN, 'px;')"/>
</xsl:if>
</xsl:attribute>
</xsl:if>
And depending on the business rules for mapping those source-attributes to style attributes change the code accordingly.
Btw.: ./# is the same as #
Use if else Function
For Example
margin-top: {if(//#TOPMARGIN!=0) then {./#TOPMARGIN, 'px'} else '12px'}
I need to create the attribute dynamically.
Actually, you want to populate the attribute dynamically - which could be done by applying a template to each input attribute you want to use:
<xsl:template match="Table">
<table>
<xsl:attribute name="style">
<xsl:apply-templates select="#BORDERLINESTYLE | #BOTTOMMARGIN | #WIDTH"/>
</xsl:attribute>
</table>
</xsl:template>
<xsl:template match="#BORDERLINESTYLE">
<xsl:text>border-style:</xsl:text>
<xsl:value-of select="."/>
<xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="#BOTTOMMARGIN">
<xsl:text>border-margin:</xsl:text>
<xsl:value-of select="."/>
<xsl:text>px; </xsl:text>
</xsl:template>
<xsl:template match="#WIDTH">
<xsl:text>width:</xsl:text>
<xsl:value-of select="."/>
<xsl:text>; </xsl:text>
</xsl:template>
I've the below XML line of code.
<entry colname="col3" align="left" valign="top"><para>grandchild, cousin, <content-style font-style="italic">etc</content-style>., shall be described as “lawful” and “one of the next-of-kin” or “only next-of-kin”.</para></entry>
and below XSL
<xsl:template match="entry" name="entry">
<xsl:choose>
<xsl:when test="./#namest">
<xsl:variable name="namest" select="#namest" />
<xsl:variable name="nameend" select="#nameend" />
<xsl:variable name="namestPos" select="count(ancestor::tgroup/colspec[#colname=$namest]/preceding-sibling::colspec)" />
<xsl:variable name="nameendPos" select="count(ancestor::tgroup/colspec[#colname=$nameend]/preceding-sibling::colspec)" />
<td colspan="{$nameendPos - $namestPos + 1}" align="{#align}">
<xsl:apply-templates select="child::node()[not(self::page)]" />
</td>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:if test="./#morerows">
<xsl:attribute name="rowspan">
<xsl:value-of select="number(./#morerows)+1" />
</xsl:attribute>
</xsl:if>
<xsl:if test="./#align">
<xsl:attribute name="align">
<xsl:value-of select="#align" />
</xsl:attribute>
</xsl:if>
<xsl:if test="./#valign">
<xsl:attribute name="valign">
<xsl:value-of select="#valign" />
</xsl:attribute>
</xsl:if>
<xsl:for-each select="para">
<div class="para">
<xsl:choose>
<xsl:when test="../#colname='col3' and contains(./text(),'.')">
<xsl:variable name="strl">
<xsl:value-of select="fn:string-length(fn:substring-before(.,'.'))" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$strl < '6'">
<a href="{concat('er:#SCP_ORD_',//chapter/#num,'/','P',translate(./text(),'.','-'))}">
<xsl:value-of select="./text()" />
</a>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:for-each>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
and when i run this on my XML in the above mentioned line(the XML given in the sample), it is throwing me an error. and the error is as below.
Wrong occurrence to match required sequence type - Details: - XPTY0004: The supplied sequence ('2' item(s)) has the wrong occurrence to match the sequence type xs:string ('zero or one')
here what i actually was trying to achieve is, i have another table(which is basically a TOC), where in there is some linking needed, and below is such sample entries.
<entry colname="col3" align="right" valign="top"><para>A.1</para></entry>
<entry colname="col3" align="right" valign="top"><para>A.2</para></entry>
here i'm searching if the colname is col3 and if this has a . in it, and the above two cases mentioned are passing and are getting linked successfully, where in the case mentioned in the top is throwing the error, can anyone please suggest some better method to differentiate these two cases, and i use XSLT 2.0.
Thanks
The problem is
contains(./text(),'.')
./text() is not "the text of the current element" but rather the sequence of all text node children of the current element. In the case of
<para>grandchild, cousin, <content-style font-style="italic">etc</content-style>., shall be described as “lawful” and “one of the next-of-kin” or “only next-of-kin”.</para>
there are two such nodes, one containing everything between the <para> and <content-style> tags ("grandchild, cousin, " including the trailing space) and the other containing everything between the </content-style> and the </para>. But the contains function expects its first argument to be a single string, not a sequence of two nodes.
Instead of testing ./text() you probably just need to test .:
contains(., '.')
which is interpreted as the string value of the whole para element, i.e. a single string consisting of the concatenation of all the descendant text nodes (so the whole text "grandchild, cousin, etc., shall be described...").
I'm trying to set parttext to #head if use_head="true" is not present and to the contents of <head> </head> if use_head="true" is present
<xsl:template match="toc_part">
<xsl:variable name="artnum">
<xsl:value-of select="../#num" />
</xsl:variable>
<xsl:variable name="partnum">
<xsl:value-of select="#num" />
</xsl:variable>
<xsl:variable name="parttext">
<xsl:if test="#use_head">
<xsl:value-of select="head"/>
</xsl:if>
<xsl:if test="not[#use_head]">
<xsl:value-of select="#head"/>
</xsl:if>
</xsl:variable>
<tr>
<td>
</td>
<td>
<a class="int" href="{$GBLfilePre}{$artnum}.html#{$artnum}{$partnum}"><xsl:text>Part </xsl:text><xsl:value-of select="$partnum" /></a>
</td>
<td>
<xsl:value-of select="$parttext" />
</td>
</tr>
</xsl:template>
I've also tried:
<xsl:if test="#use_head"><xsl:variable name="parttext"><xsl:value-of select="head"></xsl:variable>
<xsl:if test="not[#use_head"]><xsl:variable name="parttext"><xsl:value-of select="#head"></xsl:variable>
which give parttext undefined when referenced.
Try:
<xsl:variable name="parttext">
<xsl:choose>
<xsl:when test="#use_head='true'">
<xsl:value-of select="head"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#head"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Your current test in the first if statement will evaluate to true() if the #use_head attribute exists, regardless of it's value. If you want the test to evaluate whether or not it's value is equal to "true" you should use test="#use_head='true'".
The second if statement is evaluating whether or not there is an element named "not" that has an attribute called "use_head", because the square brackets are a predicate. I believe you had intended to use the not() function: not(#use_head='true')
You could then use an <xsl:choose> instead of two if blocks:
<xsl:variable name="parttext">
<xsl:choose>
<xsl:when test="#use_head='true'">
<xsl:value-of select="head"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#head"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
In XSLT 2.0:
<xsl:variable name="head"
select="if (#use_head='true') then head else #head"/>
In XSLT 1.0, either Hansen's solution, or
<xsl:variable name="head"
select="head[current()/#use_head='true'] |
#head[not(current()/#use_head='true')]"/>
In future, please tell us which version of XSLT you are using. One can sort of guess this must be XSLT 1.0 because in 2.0 the solution is trivial, but it's better not to have to guess.
I've the code as shown below which gives Stylesheet Compilation error.
<xsl:template match="form">
<xsl:copy>
<xsl:for-each select="#*">
<xsl:variable name="param" select="name(.)" />
<xsl:choose>
<xsl:when test="$param = 'name'">
<xsl:attribute name="name"><xsl:value-of
select="#name" /></xsl:attribute>
</xsl:when>
<xsl:when test="$param = 'action'">
<xsl:attribute name="action"><xsl:value-of
select="java:com.hp.cpp.proxy.util.URLUtils.rewriteAction($response, $baseurl, #action, $scope)" /></xsl:attribute>
</xsl:when>
<xsl:when test="$param = 'method'">
<xsl:attribute name="method">POST</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="$param"><xsl:value-of
select="." /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<input type="hidden" name="httpmethod">
<xsl:attribute name="value"> <xsl:value-of
select="#method" /></xsl:attribute>
</input>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
I'm trying to re-write FORM tag of HTML with quite complex requirement. Hope you'll be able to identify by the code-snap. I'm trying to re-write only few of the attributes of the tag and trying to retain the rest. Is it the right way? Any other way to do it? Any suggestion.
Thanks in advance.
-Rikin
Just a guess. Try to replace the last apply
<xsl:apply-templates select="node()|#*" />
by this
<xsl:apply-templates select="node()" />
About the compilation error, you don't provide enough information to help; Abel's conjecture that the compilation error has to do with your call to an extension function is plausible.
You also ask Is this the right way? to achieve your goal. Maybe. Your first problem here is the logic error that jvverde has already pointed to. The call to apply templates should not select attributes; you have already dealt with all the attributes. So it's unnecessary to process them again. It's also a bad idea: if you you try to handle the form element's attributes again, you'll get a run-time error because you've already written content to the element (namely that input element).
I think some XSLT programmers would write something that looks more like this:
<xsl:template match="form">
<xsl:copy>
<!--* don't use a for-each to handle the
* attributes; use templates. *-->
<xsl:apply-templates select="#*"/>
<!--* you don't need an xsl:attribute constructor
* if you want to use an expression within a
* literal result element; just braces in the
* attribute-value template.
*-->
<input type="hidden"
name="httpmethod"
value="{#method}" />
<!--* change your apply-templates call to
* select children, but not attributes.
*-->
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
<!--* now the attributes ... *-->
<xsl:template match="form/#action">
<xsl:attribute name="action">
<xsl:value-of select="java:com.hp.cpp.proxy.util.URLUtils.rewriteAction(
$response, $baseurl, #action, $scope)" />
</xsl:attribute>
</xsl:template>
<xsl:template match="form/#method">
<xsl:attribute name="method">
<xsl:value-of select="'POST'"/>
</xsl:attribute>
</xsl:template>
i'm having the below XML Document.
<?xml version="1.0" encoding="UTF-8"?>
<chapter num="A">
<title>
<content-style font-style="bold">PART 1 GENERAL PRINCIPLES</content-style>
</title>
<section level="sect1">
<title>
<content-style font-style="bold">Chapter 2: PREVENTING COMMERCIAL DISPUTES</content-style>
</title>
<section level="sect2" number-type="manual" num="1.">
<title>INTRODUCTION</title>
<para>
<phrase>2.001</phrase> With increasing competition in the business environment and the need to provide value for money to customers, most, if not all businesses, cannot afford to continuously be engaged in the dispute resolution arena as though it were a part of their core business. If all the disputes of a business entity have to be litigated or arbitrated to the bitter end, then this will become a substantial drain on its financial resources and big distraction for its management. Prolonged engagement in litigation and arbitration will undoubtedly have a detrimental effect on the business.</para>
<para>
<phrase>2.002</phrase> Preventing or minimising disputes requires businesses to know and understand the people they are dealing with and they will also need to ensure that the governing contracts are clearly and carefully drafted in order to safeguard the rights of both parties. The parties need to devote resources to train their employees to carefully and skilfully monitor the performance of the contracts and to maintain proper and adequate documentary records. This requires financial investment which some businesses are unable or reluctant to budget for. However, those businesses which have a keen awareness of the need to prevent or minimise disputes and are willing to provide the financial investment to attain this will find that, with a manageable preventative dispute resolution philosophy in place, this will, in the long term, be cost-effective and above all, create an environment that preserves close working relationships.</para>
</section>
<section level="sect2" number-type="manual" num="2.">
<title>SELECTING A COUNTERPARTY</title>
<para>
<phrase>2.003</phrase> Commercial disputes inevitably arise between two or more parties under a commercial contract. The attributes of the counterparty with which one contracts will therefore have an impact on whether disputes can be prevented or, even if not, whether disputes can be resolved in an efficient and cost-effective manner, which will ultimately benefit both parties.</para>
<para>
<phrase>2.004</phrase> Consideration should be given to certain aspects of the counterparty before a contract is entered into. These attributes of a contracting party can impact on whether the relationship is likely to go smoothly or whether it is going to be “dispute prone”.</para>
<section level="sect2" number-type="manual" num="(a)">
<title>Financial power</title>
<para>
<phrase>2.005</phrase> A contracting party which has financial substance is, in general, more likely to be willing to abide by their contractual obligations, simply because they are relatively easy targets of a lawsuit. On the other hand, where one contracts with an insubstantial or “fly-by-night” party, there is a genuine concern that, once the contract becomes unprofitable or if something goes wrong, there is a bigger propensity for disputes to arise as a result of the latter seeking to avoid its obligations.</para>
</section>
<section level="sect2" number-type="manual" num="(b)">
<title>Market reputation</title>
<para>
<phrase>2.006</phrase> A contracting party which has a market reputation it wishes to safeguard is likely to be more careful in the type of disputes it would be likely to get involved in. Listed companies or those which have a public image to preserve are, in general, more likely to avoid litigating every claim irrespective of size (unless such claims, if not litigated, are liable to open up floodgates) to minimise the bad publicity associated with being in the courts too often, or giving the impression to potential future contracting parties that they are litigious and difficult to deal with.</para>
</section>
<section level="sect2" number-type="manual" num="(c)">
<title>Location and culture</title>
<para>
<phrase>2.007</phrase> This is a sensitive topic and therefore there will be no specific references. However, a discussion of this type would be incomplete without acknowledging the fact that businesses or projects in certain parts of the world are more prone to conflicts or natural disasters and are more likely to end up in disputes than those in more “peaceful” parts of the world. Certain cultures tend also to be more litigious than others, and when contracting with parties of certain cultural backgrounds that focus less on mutual tolerance and co-operation, there will be more expectation of disputes.</para>
</section>
<section level="sect2" number-type="manual" num="(d)">
<title>Focus/investment on risk prevention</title>
<para>
<phrase>2.008</phrase> Certain contracting parties, more often seen in developed countries, have a better awareness of the law and the need to invest in risk prevention in order to minimise the probability of disputes. “Investments” in this regard include spending money to vet their business partners, including investigating their financial status and their market reputation, and allowing their legal department a sufficient budget to properly review draft contracts, assist with negotiations and to keep fully up-to-date with the latest legal developments.</para>
</section>
</section>
<section level="sect2" number-type="manual" num="3.">
<title>CONTRACT NEGOTIATION AND DRAFTING</title>
<para>
<phrase>2.009</phrase> There are two basic ways in which conflicts can be avoided without the need for the use of dispute resolution mechanisms. The first is the use of negotiation skills to negotiate a contract that affords the best terms and conditions possible, covering all or most foreseeable contingencies. Having clear and favourable provisions in a contract puts a party in a better position, especially when it is sought to resolve disputes at their source, without the need to revert to the dispute resolution mechanisms provided for in the contract. This, without a doubt, is the cheapest and most effective means of avoiding disputes or resolving possible disputes. The importance of contract negotiations should not be lightly dismissed.</para>
<para>
<phrase>2.010</phrase> The second is having a clearly drafted contract that is well thought out and planned and serves everyone’s interests. Often a hastily drafted contract that is put together at the last minute results in uncertainty and vagueness of terms which could potentially create disputes. The inclusion of appropriate clauses (for example, clauses that cover force majeure or hardship) provide for changing conditions that may render the contract impossible to perform are of major importance. The drafting of such clauses is relatively technical in nature and requires the skills of a competent drafter of commercial contracts to ensure that they are manageable from a commercial standpoint.</para>
<para>
<phrase>2.011</phrase> An area to be aware of is the use of standard form contracts and adopting such forms within the existing framework of the contract. Although there are a variety of such standard form contracts available in the market place to be referred to, care must be taken, as these forms are only a guide to assist in the drafting of a contract that suits individual needs. Consulting legal counsel for advice is beneficial, especially when the contract touches on issues such as jurisdiction, which can often be difficult concepts for a lay person to understand.</para>
<para>
<phrase>2.012</phrase> The drafting of specialist contracts such as those in the construction, insurance, commodity and maritime fields requires a great deal of industry knowledge and experience to ensure that suitable wording is used to minimise the chances of disputes. However, regardless of the type of contract involved, there are certain provisions which are generic in nature, and the inclusion of which will generally (although not always) minimise the scope of the disputes between the parties, and are usually good to have. These provisions are often referred to as boilerplate clauses.</para>
<para>
<phrase>2.013</phrase> The importance of boilerplate clauses is often overlooked as the parties tend to focus on the commercial terms of the contract, such as the cost of the goods or services being provided. Failure to include appropriate boilerplate clauses may prevent a party from effectively enforcing its rights under the contract and offer an escape route to the defaulting party from its liabilities.</para>
</section>
</section>
</chapter>
and when i apply the below xslt, the counter in section (taken as ), everytime a new section with number in num is found, the counter is getting reset to 1 but if the num is having value like (a),(b) .. it is continuing, what i want is, the counter should be never be reset to 1. please help me in acheiving this.
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" exclude-result-prefixes="ntw">
<xsl:variable name="ThisDocument" select="document('')"/>
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><!DOCTYPE></xsl:text>
<html>
<head>
<xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
<title>
<xsl:value-of select="substring-after(chapter/section/title,':')"/>
</title>
<link rel="stylesheet" href="er:#css" type="text/css"/><xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
</head>
<body>
<xsl:apply-templates/>
<section class="tr_footnotes">
<hr/>
<xsl:apply-templates select="//footnote" mode="footnote"/>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="chapter">
<section class="tr_chapter">
<div class="chapter">
<xsl:variable name="l">
<xsl:value-of select="substring(substring-after(section/title,' '),1,1)"/>
</xsl:variable>
<a name="AHK_CH_0{$l}"/>
<div class="chapter-title">
<xsl:variable name="titl">
<xsl:value-of select="substring-after(section/title,':')"/>
</xsl:variable>
<span class="chapter-num">
<xsl:value-of select="concat('Chapter ',$l,' ')"/>
</span>
<xsl:value-of select="$titl"/>
</div>
<div class="para align-center">
<span class="font-style-italic">
<xsl:value-of select="document('AHK-authors.xml')/chapters/chapter[#no=$l]"/>
</span>
</div>
<div class="para align-right"><span class="format-smallcaps">Para</span>.</div>
<div class="toc">
<div class="toc-part">
<table class="toc-div">
<tbody>
<tr>
<td>
<xsl:for-each select="current()/section/section|current()/section/section/section[contains(#num, '(')]|current()/section/section/section/section[contains(#num, '(')]">
<xsl:call-template name="IndexItem">
</xsl:call-template>
</xsl:for-each>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<xsl:apply-templates select="section/section"/>
</div>
</section>
</xsl:template>
<xsl:template match="chapter/para">
<div class="para align-right">
<span class="format-smallcaps">Para</span>.
</div>
<xsl:apply-templates select="section"/>
</xsl:template>
<xsl:template name="fig" match="figure">
<div class="figure">
<div class="figure-title">
<xsl:value-of select="current()/title"/>
</div>
<xsl:variable name="numb">
<xsl:value-of select="substring-after(graphic/#href,'_')"/>
</xsl:variable>
<xsl:variable name="figCon">
<xsl:value-of select="concat('er:#page-',$numb)"/>
</xsl:variable>
<img class="graphic" src="{$figCon}" alt=""/>
</div>
</xsl:template>
<xsl:template name="IndexItem">
<xsl:if test="not(contains(#level,'sect1'))"><!--changed fron #num to sect2-->
<xsl:variable name="tocpg">
<xsl:value-of select="concat('#P',descendant::para/phrase[1]/text())"/>
</xsl:variable>
<xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')"/>
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="text" select="current()/title/text()"/>
<xsl:variable name="Brac">
<xsl:choose>
<xsl:when test="contains(current()/#num,'(')">
<xsl:value-of select="2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="d">
<xsl:value-of select="concat('toc-item-',$ThisDocument//ntw:nums[#num=$Brac]/#word,'-level')"/>
</xsl:variable>
<table class="{$d}">
<tbody>
<tr>
<td class="toc-item-num">
<xsl:value-of select="#num"/>
</td>
<td class="toc-title">
<xsl:value-of select="concat(substring($text,1,1), translate(substring($text,2), $uppercase, $smallcase))"/>
</td>
<td class="toc-pg">
<a href="{$tocpgtag}">
<xsl:value-of select="descendant::para/phrase[1]/text()"/>
</a>
</td>
</tr>
</tbody>
</table>
</xsl:if>
</xsl:template>
<!-- Index Templates Complete -->
<!-- Paragraph templates -->
<xsl:template name="section" match="section">
<!-- Variables-->
<xsl:variable name="classname">
<!--Get name attribute of current node -->
<xsl:value-of select="concat('section-',parent::section/#level)"/>
</xsl:variable>
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:variable name="StrL">
<xsl:value-of select="string-length(substring(substring-after(ancestor::chapter/section/title,'Chapter '),1,1))"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$StrL>1">
<xsl:value-of select="substring(substring-after(ancestor::chapter/section/title,'Chapter '),1,1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('0',substring(substring-after(ancestor::chapter/section/title,'Chapter '),1,1))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sectnum">
<xsl:number 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 -->
<div class="{$classname}">
<a name="{$sectionname}"> </a>
<div class="section-title">
<span class="section-num">
<xsl:value-of select="#num"/>
<xsl:text> </xsl:text>
</span>
<xsl:apply-templates select="title"/>
</div>
<xsl:apply-templates select="child::node()[not(self::title)]"/>
</div>
</xsl:template>
<xsl:template name="para" match="section/para">
<div class="para">
<xsl:apply-templates select="phrase"/>
<span class="phrase">
<xsl:value-of select="current()/phrase"/>
</span>
<xsl:choose>
<xsl:when test="contains(current()/text(),'Chapter')">
<xsl:variable name="x">
<xsl:value-of select="substring(substring-before(current()/text(),'Chapter'),1)"/>
</xsl:variable>
<xsl:variable name="y">
<xsl:value-of select="substring(substring-after(current()/text(),'Chapter'),4)"/>
</xsl:variable>
<xsl:variable name="z">
<xsl:value-of select="normalize-space(substring-before(substring-after(current()/text(),'Chapter'),'.'))"/>
</xsl:variable>
<xsl:variable name="h">
<xsl:value-of select="string-length($z)"/>
</xsl:variable>
<xsl:value-of select="$x"/>
<xsl:choose>
<xsl:when test="$h =1">
<a href="{concat('er:#AHK_CH_0',$z,'/AHK_CH_0',$z)}">
<xsl:value-of select="concat('Chapter',$z)"/>
</a>
</xsl:when>
<xsl:otherwise>
<a href="{concat('er:#AHK_CH_',$z,'/AHK_CH_',$z)}">
<xsl:value-of select="concat('Chapter',$z)"/>
</a>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$y "/>
<xsl:apply-templates select="footnote"/>
<xsl:apply-templates select="current()/phrase/text()"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="child::node()[not(self::phrase)]"/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<xsl:template name="phrase" match="phrase">
<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:template>
<!-- Table Templates -->
<xsl:template name="table" match="table">
<table style="frame-{current()/#frame} width-{translate(current()/#width,'%','')}">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="tgroup">
<colgroup>
<xsl:apply-templates select=".//colspec"/>
</colgroup>
<xsl:apply-templates select="child::node()[not(self::colspec)]"/>
</xsl:template>
<xsl:template name="tbody" match="tgroup/tbody">
<tbody>
<xsl:for-each select="current()/row">
<xsl:call-template name="row"/>
</xsl:for-each>
</tbody>
</xsl:template>
<xsl:template name="thead" match="tgroup/thead">
<xsl:for-each select="current()/row"><thead>
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="headentry"/>
</xsl:for-each>
</tr>
</thead>
</xsl:for-each>
</xsl:template>
<xsl:template name="colspec" match="colspec">
<col class="colnum-{current()/#colnum} colname-{current()/#colname} colwidth-{translate(current()/#colwidth,'%','')}"/>
</xsl:template>
<xsl:template name="row" match="tbody/row">
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="entry"/>
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template name="entry" match="entry">
<xsl:variable name="count">
<xsl:value-of select="count(preceding-sibling::* | following-sibling::*)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$count < 2">
<xsl:if test="position()=1">
<td>
<div class="para align-center">
<xsl:value-of select="para[position()=1]"/>
</div>
</td>
<td>
<div class="para">
<xsl:value-of select="following-sibling::node()"/>
</div>
</td>
</xsl:if>
</xsl:when>
<xsl:when test="$count > 1">
<td>
<div class="para">
<xsl:apply-templates/>
</div>
</td>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="headentry">
<th>
<xsl:if test="translate(current()/#namest,'col','') != translate(current()/#nameend,'col','')">
<xsl:variable name="colspan">
<xsl:value-of select="translate(current()/#nameend,'col','') - translate(current()/#namest,'col','') + 1"/>
</xsl:variable>
<xsl:attribute name="colspan"><xsl:value-of select="$colspan"></xsl:value-of></xsl:attribute>
</xsl:if>
<div class="para">
<xsl:value-of select="current()/para/text()"/>
<xsl:apply-templates/>
</div>
</th>
</xsl:template>
<!-- Table Templates complete -->
<!--List templates -->
<xsl:template name="orderedlist" match="orderedlist">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template name="orderitem" match="item">
<li class="item">
<xsl:apply-templates/>
</li>
</xsl:template>
<xsl:template name="orderitempara" match="item/para">
<div class="para">
<span class="item-num">
<xsl:if test="position()=1">
<xsl:value-of select="parent::item[1]/#num"/>
<xsl:text> </xsl:text>
</xsl:if>
</span>
<xsl:apply-templates/>
</div>
</xsl:template>
<!--List templates Complete -->
<!-- Paragraph templates Complete -->
<!-- Footnote Templates-->
<xsl:template match="footnote">
<sup>
<a>
<xsl:attribute name="name"><xsl:text>f</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#ftn.</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute>
<xsl:number level="any" count="footnote" format="1"/>
</a>
</sup>
</xsl:template>
<xsl:template match="footnote" mode="footnote">
<div class="tr_footnote">
<div class="footnote">
<sup>
<a>
<xsl:attribute name="name"><xsl:text>ftn.</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#f</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute>
<xsl:number level="any" count="footnote" format="1"/>
</a>
</sup>
<div class="a">
<xsl:variable name="new">
<xsl:value-of select="current()"/>
</xsl:variable>
<xsl:variable name="new1">
<xsl:value-of select="substring(substring-after(current(),'paragraph'),2,5)"/>
</xsl:variable>
<xsl:variable name="roo">
<xsl:value-of select="substring(//#num,2)"/>
</xsl:variable>
<xsl:variable name="befTex">
<xsl:value-of select="substring-before(current(),'paragraph')"/>
</xsl:variable>
<xsl:variable name="before">
<xsl:value-of select="substring-before($new1,'.')"/>
</xsl:variable>
<xsl:variable name="after">
<xsl:value-of select="substring(substring-after($new1,'.'),1,3)"/>
</xsl:variable>
<xsl:variable name="centTex">
<xsl:value-of select="substring(substring-after(current(),$after),1)"/>
</xsl:variable>
<xsl:variable name="pCon">
<xsl:value-of select="concat('paragraph',' ',$before,'.',$after)"/>
</xsl:variable>
<xsl:variable name="tes">
<xsl:if test="contains($centTex,'chapter')">
<xsl:value-of select="concat(' ',substring(substring-before($centTex,'chapter'),2))"/>
</xsl:if>
</xsl:variable>
<xsl:variable name="ChapNu">
<xsl:value-of select="normalize-space(substring(substring-after(current(),'chapter'),1,2))"/>
</xsl:variable>
<xsl:variable name="ChapNuC">
<xsl:value-of select="concat('er:#BVI_CH_0',$ChapNu,'/BVI_CH_0',$ChapNu)"/>
</xsl:variable>
<xsl:variable name="curSel">
<xsl:value-of select="concat('#P',$before,'-',$after)"/>
</xsl:variable>
<xsl:variable name="ChapCon">
<xsl:value-of select="concat('chapter',' ',substring(substring-after(current(),'chapter'),2,1))"/>
</xsl:variable>
<xsl:variable name="conc1">
<xsl:value-of select="concat('er:#BVI_CH_0',$before,'/P',$before,'-',$after)"/>
</xsl:variable>
<xsl:value-of select="$befTex"/>
<xsl:choose>
<xsl:when test="contains(substring(substring-after($new,'paragraph'),1,3),'.')">
<xsl:choose>
<xsl:when test="$before = $roo">
<a href="{$curSel}">
<xsl:value-of select="$pCon"/>
</a>
</xsl:when>
<xsl:otherwise>
<a href="{$conc1}">
<xsl:value-of select="$pCon"/>
</a>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$tes"/>
<xsl:if test="contains($centTex,'chapter')">
<a href="{$ChapNuC}">
<xsl:value-of select="$ChapCon"/>
</a>
</xsl:if>
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</div>
</div>
</div>
</xsl:template>
<xsl:template match="footnote/para/uri">
<xsl:variable name="url1">
<xsl:value-of select="translate(#href, '<','')" />
</xsl:variable>
<xsl:variable name="url2">
<xsl:value-of select="translate($url1, '>','')" />
</xsl:variable>
<a href="{$url2}">
<xsl:value-of select="." />
</a>
</xsl:template>
<!-- Footnote Templates Complete -->
<xsl:template match="content-style">
<xsl:choose>
<xsl:when test="#format='smallcaps'">
<xsl:value-of select="translate(normalize-space(.),'ABCDEFGHIJKLMNOPQRSTUVWXZ','abcdefghijklmnopqrstuvwxyz')"/>
</xsl:when>
<xsl:when test="#format='superscript'">
</xsl:when>
<xsl:otherwise>
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',#font-style)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:apply-templates/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Namespace ntw-->
<ntw:nums num="1" word="first"/>
<ntw:nums num="2" word="second"/>
<ntw:nums num="3" word="third"/>
<ntw:nums num="4" word="forth"/>
<ntw:nums num="5" word="fifth"/>
<ntw:nums num="6" word="sixth"/>
<ntw:nums num="7" word="seventh"/>
<ntw:nums num="8" word="eighth"/>
<ntw:nums num="9" word="nighth"/>
<ntw:nums num="10" word="tenth"/>
<!-- Namespace ntw ends -->
</xsl:stylesheet>
Thanks
I've used the counter value as 1 in the below code, but i\ need to use the code given in the second block below.
<xsl:variable name="sectionname">
<xsl:value-of select="concat('CH_',$chapternumber,'-SEC-', $sectnum)"/>
</xsl:variable>
<xsl:variable name="sectnum">
<xsl:for-each select="Current()">
<xsl:value-of select="count(preceding-sibling::*)"/>
</xsl:for-each/>
</xsl:variable>
and this will give the value.