Hi ALL,
As i am new to XSLT i am not able to implement the logic,
Please share your views if any know's how do this.

i have an xml

<?xml version="1.0" encoding="UTF-8" ?> 
<?xml-stylesheet type="text/xsl" href="Temp.xsl"?>
<Rowsets DateCreated="2011-02-14T12:24:00" EndDate="2011-02-14T12:24:00" StartDate="2011-02-14T11:24:00" Version="12.0.2 Build(88)">
	<Rowset>
		<Columns>
			<Column Description="BatchNumber" MaxRange="1" MinRange="0" Name="BatchNumber" SQLDataType="12" SourceColumn="BatchNumber" /> 
			<Column Description="VersionCode" MaxRange="1" MinRange="0" Name="VersionCode" SQLDataType="3" SourceColumn="VersionCode" /> 
			<Column Description="MaterialType" MaxRange="1" MinRange="0" Name="MaterialType" SQLDataType="12" SourceColumn="MaterialType" /> 
			<Column Description="LotNumber" MaxRange="1" MinRange="0" Name="LotNumber" SQLDataType="4" SourceColumn="LotNumber" /> 
			<Column Description="RRComplete" MaxRange="1" MinRange="0" Name="RRComplete" SQLDataType="-6" SourceColumn="RRComplete" /> 
			<Column Description="ReviewerName" MaxRange="1" MinRange="0" Name="ReviewerName" SQLDataType="12" SourceColumn="ReviewerName" /> 
			<Column Description="ReviewStartDate" MaxRange="1" MinRange="0" Name="ReviewStartDate" SQLDataType="93" SourceColumn="ReviewStartDate" /> 
			<Column Description="ReviewEndDate" MaxRange="1" MinRange="0" Name="ReviewEndDate" SQLDataType="93" SourceColumn="ReviewEndDate" /> 
			<Column Description="ProjectedEndDate" MaxRange="1" MinRange="0" Name="ProjectedEndDate" SQLDataType="93" SourceColumn="ProjectedEndDate" /> 
			<Column Description="DispositionerName" MaxRange="1" MinRange="0" Name="DispositionerName" SQLDataType="12" SourceColumn="DispositionerName" /> 
			<Column Description="ReceiptDate" MaxRange="1" MinRange="0" Name="ReceiptDate" SQLDataType="93" SourceColumn="ReceiptDate" /> 
			<Column Description="TargetDispositionDate" MaxRange="1" MinRange="0" Name="TargetDispositionDate" SQLDataType="93" SourceColumn="TargetDispositionDate" /> 
			<Column Description="DRComplete" MaxRange="1" MinRange="0" Name="DRComplete" SQLDataType="-6" SourceColumn="DRComplete" /> 
			<Column Description="DispositionedDate" MaxRange="1" MinRange="0" Name="DispositionedDate" SQLDataType="93" SourceColumn="DispositionedDate" /> 
			<Column Description="RecommendedUsageDecision" MaxRange="1" MinRange="0" Name="RecommendedUsageDecision" SQLDataType="12" SourceColumn="RecommendedUsageDecision" /> 
			<Column Description="FinalUsageDecision" MaxRange="1" MinRange="0" Name="FinalUsageDecision" SQLDataType="12" SourceColumn="FinalUsageDecision" /> 
			<Column Description="BatchStatus" MaxRange="1" MinRange="0" Name="BatchStatus" SQLDataType="12" SourceColumn="BatchStatus" />  
			<Column Description="Plant" MaxRange="1" MinRange="0" Name="Plant" SQLDataType="12" SourceColumn="Plant" /> 
			<Column Description="MaterialNumber" MaxRange="1" MinRange="0" Name="MaterialNumber" SQLDataType="12" SourceColumn="MaterialNumber" /> 
			<Column Description="MaterialDescription" MaxRange="1" MinRange="0" Name="MaterialDescription" SQLDataType="-1" SourceColumn="MaterialDescription" /> 
			<Column Description="DateOfManufacture" MaxRange="1" MinRange="0" Name="DateOfManufacture" SQLDataType="93" SourceColumn="DateOfManufacture" /> 
			<Column Description="ExpiryDate" MaxRange="1" MinRange="0" Name="ExpiryDate" SQLDataType="93" SourceColumn="ExpiryDate" /> 
			<Column Description="QuantityManufactured" MaxRange="1" MinRange="0" Name="QuantityManufactured" SQLDataType="12" SourceColumn="QuantityManufactured" /> 
			<Column Description="BatchComments" MaxRange="1" MinRange="0" Name="BatchComments" SQLDataType="-1" SourceColumn="BatchComments" />
			<Column Description="Stock" MaxRange="1" MinRange="0" Name="Stock" SQLDataType="-1" SourceColumn="Stock" />
		</Columns>
	<Row>
		<BatchNumber>A12345</BatchNumber> 
		<VersionCode>1</VersionCode> 
		<MaterialType>Raw</MaterialType> 
		<LotNumber>12345</LotNumber> 
		<RRComplete>0</RRComplete> 
		<ReviewerName>Ankit</ReviewerName> 
		<ReviewStartDate>2011-02-08T00:00:00</ReviewStartDate> 
		<ReviewEndDate>2011-02-15T00:00:00</ReviewEndDate> 
		<ProjectedEndDate>TimeUnavailable</ProjectedEndDate> 
		<DispositionerName>Ankit</DispositionerName> 
		<ReceiptDate>2011-02-01T00:00:00</ReceiptDate> 
		<TargetDispositionDate>2011-06-11T00:00:00</TargetDispositionDate> 
		<DRComplete>0</DRComplete> 
		<DispositionedDate>TimeUnavailable</DispositionedDate> 
		<RecommendedUsageDecision>---</RecommendedUsageDecision> 
		<FinalUsageDecision>---</FinalUsageDecision> 
		<BatchStatus>---</BatchStatus> 
		<Plant>PR12</Plant> 
		<MaterialNumber>A00003434</MaterialNumber> 
		<MaterialDescription>No breaks</MaterialDescription> 
		<DateOfManufacture>2010-12-02T00:00:00</DateOfManufacture> 
		<ExpiryDate>1930-03-05T00:00:00</ExpiryDate> 
		<QuantityManufactured>69.3454LT</QuantityManufactured> 
		<BatchComments>---</BatchComments> 
		<Stock>Resticted</Stock>
		
	</Row>
	</Rowset>
</Rowsets>

I am attaching the followoing XSLT to generate a report using this XML data...
XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
<xsl:template match="/">
    <xsl:apply-templates select="Rowsets/Rowset"/>
</xsl:template>
<xsl:template match="Rowsets/Rowset">
<html>
<head>
<title> In Process Batch Details </title>
<style>
*{
    font: 8pt verdana;
}
body {
	background-color:#F6F7FB;
	display: block;
	page: Report;
	counter-reset: page 1
}
<!-- Sizing the page -->
@page { size: A4 portrait; } 

<!-- Conter to show line number while printing -->
@page main {
    @top { content: string(chapter-title) }
    @bottom {
        content: "Page " counter(page) " of " counter(pages)
    }
}
chapter title { string-set: chapter-title content() }


table { empty-cells: show; border-spacing: 0px; margin: 0px; padding: 0px;  align:center}
	.pagebreak {page-break-after: always;}
	.tableReportHeader{border-top: solid #4A6ACC 1px; border-left: solid #4A6ACC 1px; border-right: solid #4A6ACC 1px; width: 645px;}
	.tabledetails{border-left: solid #4A6ACC 1px; border-right: solid #4A6ACC 1px;  width: 645px; }
	.tableReportFooter{bottom: 2px;border-bottom: solid #4A6ACC 1px; border-left: solid #4A6ACC 1px; border-right: solid #4A6ACC 1px;  width: 645px;}
	.imglogo{border-style: none; vertical-align: top; border-color: #F6F7FB;}
	td{vertical-align: top; font-family: Arial, Helvetica, sans-serif; font-size: 9pt}
	.tdmargin{width:10px;}
	.documentheader{font-family:Arial; font-size:9pt; color:#4A6ACC; font-weight:bold;}
	th{font-family:Arial; font-size:8pt; color:white; background-color: #4A6ACC; text-align:center;border: solid 1px darkblue;}
	.tdorderHeader{border: solid 1px #4A6ACC;}
	.blueline{border-bottom: solid #4A6ACC 1px;}
	.documenttotal{font-family:Arial; font-size:9pt; color:#4A6ACC; font-weight:bold;border-bottom: solid #4A6ACC 1px;}
	.tdtotalmargin{width:450px;}
</style>
</head>
<body>
	<xsl:copy-of select="$ReportHeader"/> <!-- Company Logo, Name -->

	<xsl:call-template name="Filler">
		<xsl:with-param name="fillercount" select="1" />
	</xsl:call-template>

	<xsl:copy-of select="$middleSection"/> <!-- Section to specify Additional Details -->

	<xsl:call-template name="Filler">
		<xsl:with-param name="fillercount" select="1" />
	</xsl:call-template>

	<xsl:copy-of select="$ContentTableHeader"/>
	<xsl:for-each select="Columns/Column">
		<table class="tabledetails" cellspacing="0" style="table-layout:fixed" border="2">
			
			<tr>
				<td>
				<xsl:value-of select="@Name" />
				</td>
				<td>
				<xsl:variable name="BatchDetails" select="@Name"/>
				<xsl:value-of select="../../Row/*[local-name()=$BatchDetails]"/>
				<xsl:value-of select="translate(' ', ' ', '&#160;')"/>
				</td>
				
			</tr>
		</table>
		<xsl:if test="(position() mod 5) = 0 ">
			<!--5 rows per page-->
			
			<xsl:call-template name="Filler">
				<xsl:with-param name="fillercount" select="1" />
			</xsl:call-template>

			<xsl:copy-of select="$ReportFooter" />

			<br class="pagebreak" />

			<xsl:copy-of select="$ReportHeader" />

			<xsl:call-template name="Filler">
				<xsl:with-param name="fillercount" select="1" />
			</xsl:call-template>

			<xsl:copy-of select="$middleSection"/> <!-- Section to specify Additional Details -->

			<xsl:call-template name="Filler">
				<xsl:with-param name="fillercount" select="1" />
			</xsl:call-template>

			<xsl:copy-of select="$ContentTableHeader"/>
		</xsl:if>
	 </xsl:for-each>
</body>
</html>
</xsl:template>
<!-- ContentTableHeader -->

	<xsl:variable name="ContentTableHeader">
		<table class="tabledetails" cellspacing="0" style="table-layout:fixed" border="2">
		<tr>
			<th colspan="2">
			In Process Batch Details
			</th>
			
		</tr>
		</table>
	</xsl:variable>
<!-- variable Miidle Section-->
<xsl:variable name="middleSection">

	<table class="tabledetails" cellspacing="0" style="table-layout:fixed">
		<tr>
			<td class="tdmargin" />
			<td class="documentheader"  align="right">
				Batch #:
				<xsl:value-of select="translate(' ', ' ', '&#160;')"/>
			</td>
			<td>
				<xsl:value-of select="//Row/BatchNumber"/>
				<xsl:value-of select="translate(' ', ' ', '&#160;')"/>
			</td>
			<td class="documentheader" align="right">
				Reviewer Name:
				<xsl:value-of select="translate(' ', ' ', '&#160;')"/>
			</td>
			<td>
				<xsl:value-of select="//Row/ReviewerName" />
				<xsl:value-of select="translate(' ', ' ', '&#160;')"/>
			</td>
			<td class="tdmargin" />
		</tr>
		
	</table>
</xsl:variable>
<!-- variable ReportHeader-->
	<xsl:variable name="ReportHeader">
		<table class="tableReportHeader" cellspacing="0">
			<tr>
				<td>
					<img class="imglogo" src="report1.bmp" />
				</td>
				<td align="center">
					<img  src="ABC_Company.gif" />
				</td>
				<td ALIGN="right">
					<h3 style="color:darkblue; font-family: Arial;">BATCH DETAILS REPORT</h3>
				</td>
			</tr>
		</table>
	</xsl:variable>
<!-- Template Filler-->
	<xsl:template name="Filler">
		<xsl:param name="fillercount" select="1"/>
		<xsl:if test="$fillercount > 0">
			<table class="tabledetails">
				<tr>
					<td>
						<xsl:value-of select="translate(' ', ' ', '&#160;')"/>
					</td>
				</tr>
			</table>
			<xsl:call-template name="Filler">
				<xsl:with-param name="fillercount" select="$fillercount - 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>



<!-- variable ReportFooter-->
	<xsl:variable name="ReportFooter">
		<table class="tableReportFooter">
			<tr>
				<td style="width:20px;"></td>
				<td>
					<table>
						<tr>
							<td style="font-size:8pt; text-align: justify;border-top: solid #4A6ACC 1px;">
								Footer Details for Example  Phone:123456789   Fax:12345 Mail to : abc@xyz.com
							</td>
						</tr>
					</table>
				</td>
				<td style="width:20px;"></td>
			</tr>	
		</table>
	</xsl:variable>
</xsl:stylesheet>

I am a facing the problem like in XMl if u observe i have 20 records exactly and in my XSLT i have written a logic to show only five records per page, when i iterate through the loop , i have to implement a logic

if the record position is last and and the total record count is exactly divisible by 5 then i should break the loop, so that i will not display the header template which is not needed.


Please find the attachment for clear under standing of the problem.
I dont need the last Page in the report as shown in the screen shot.

you modify xml with xslt to html
so you can use javascript to controlled the xml output in html code

a little example
xml

<?xml version="1.0"?>
<?xml-stylesheet href="testtable.xsl" type="text/xsl" ?><root>
	<table>
		<data>1</data>
		<data>1</data>
		<data>1</data>
	</table>
	<table>
		<data>2</data>
		<data>2</data>
		<data>2</data>
	</table>
	<table>
		<data>3</data>
		<data>3</data>
		<data>3</data>
	</table>
	<table>
		<data>4</data>
		<data>4</data>
		<data>4</data>
	</table>
	<table>
		<data>5</data>
		<data>5</data>
		<data>5</data>
	</table>
	<table>
		<data>6</data>
		<data>6</data>
		<data>6</data>
	</table>
	<table>
		<data>7</data>
		<data>7</data>
		<data>7</data>
	</table>
</root>

xsl with logic

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>
	<xsl:template match="/">
		<html>
			<style type="text/css">table{
		border: solid black 2px;
		margin: 20 px;
		}
		td{
		border: solid black 2px;
		}
		.in{
		width: 40px;
		}</style>
			<script type="text/javascript">
				<xsl:text>var counter =</xsl:text>
				<xsl:value-of select="count(root/table)"/>
				<xsl:text>;
			<![CDATA[
			function on(choose){
				for (var i = 1; i <= counter; i++){
					strvalue='id'+ i;
					if (choose=='out'){
						document.getElementById(strvalue.toString()).style.display="none";
					}
					else{
						document.getElementById(strvalue.toString()).style.display="block";
					};
				}
			};
			function genau(wahl){
				document.getElementById('id'+wahl.toString()).style.display="block";
			};			
			function zeigen(){
//alert(document.getElementById('start').value + document.getElementById('end').value);
				for (var i = document.getElementById('start').value; i <= document.getElementById('end').value; i++){
					strvalue='id'+ i;
					if (document.getElementById('fall').value == 'off'){
						document.getElementById(strvalue.toString()).style.display="none";
					};
					if (document.getElementById('fall').value == 'on'){
						document.getElementById(strvalue.toString()).style.display="block";
					};
				}

			};		
			]]></xsl:text>
			</script>
			<body>
				<div>
					<table>
						<tr>
							<td></td>
							<td>stautus on|off</td>
							<td>start</td>
							<td>end</td>
						</tr>
						<tr>

							<td>
								<a href="javascript:zeigen();">run</a>
							</td>
							<td>
								<input class="in" id="fall" type="text">
									<xsl:attribute name="value">
										<xsl:text>on</xsl:text>
									</xsl:attribute>
								</input>
							</td>
							<td>
								<input class="in" id="start" type="text" value="1"/>
							</td>
							<td>
								<input class="in" id="end" type="text">
									<xsl:attribute name="value">
										<xsl:value-of select="count(root/table)"/>
									</xsl:attribute>
								</input>
							</td>
						</tr>
						<tr>
							<td>
								<a href="javascript:on('out');">all close</a>
							</td>
						</tr>
						<tr>
							<td>
								<a href="javascript:on('on');">all on</a>
							</td>
						</tr>
					</table>
				</div>
				<xsl:apply-templates select="root"/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="root">
		<xsl:apply-templates select="table"/>
	</xsl:template>

	<xsl:template match="table">
		<table>
			<xsl:attribute name="id">
				<xsl:value-of select="concat('id',position())"/>
			</xsl:attribute>
			<xsl:attribute name="style">
				<xsl:text>display:block;</xsl:text>
			</xsl:attribute>
			<xsl:apply-templates select="data"/>
		</table>
	</xsl:template>

	<xsl:template match="data">
		<tr>
			<td>
				<xsl:value-of select="."/>
			</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>

with this you can all off on or select to display

<html>
  <style type="text/css">table{
		border: solid black 2px;
		margin: 20 px;
		}
		td{
		border: solid black 2px;
		}
		.in{
		width: 40px;
		}
  </style>
  <script type="text/javascript">var counter =7;
			
			function on(choose){
				for (var i = 1; i <= counter; i++){
					strvalue='id'+ i;
					if (choose=='out'){
						document.getElementById(strvalue.toString()).style.display="none";
					}
					else{
						document.getElementById(strvalue.toString()).style.display="block";
					};
				}
			};
			function genau(wahl){
				document.getElementById('id'+wahl.toString()).style.display="block";
			};			
			function zeigen(){
//alert(document.getElementById('start').value + document.getElementById('end').value);
				for (var i = document.getElementById('start').value; i <= document.getElementById('end').value; i++){
					strvalue='id'+ i;
					if (document.getElementById('fall').value == 'off'){
						document.getElementById(strvalue.toString()).style.display="none";
					};
					if (document.getElementById('fall').value == 'on'){
						document.getElementById(strvalue.toString()).style.display="block";
					};
				}

			};		
			
  </script>
  <body>
    <div>
      <table>
        <tr>
          <td></td>
          <td>stautus on|off</td>
          <td>start</td>
          <td>end</td>
        </tr>
        <tr>
          <td>
            <a href="javascript:zeigen();">run</a>
          </td>
          <td>
            <input class="in" id="fall" type="text" value="on">
          </td>
          <td>
            <input class="in" id="start" type="text" value="1">
          </td>
          <td>
            <input class="in" id="end" type="text" value="7">
          </td>
        </tr>
        <tr>
          <td>
            <a href="javascript:on('out');">all close</a>
          </td>
        </tr>
        <tr>
          <td>
            <a href="javascript:on('on');">all on</a>
          </td>
        </tr>
      </table>
    </div>
    <table id="id1" style="display:block;">
      <tr>
        <td>1</td>
      </tr>
      <tr>
        <td>1</td>
      </tr>
      <tr>
        <td>1</td>
      </tr>
    </table>
    <table id="id2" style="display:block;">
      <tr>
        <td>2</td>
      </tr>
      <tr>
        <td>2</td>
      </tr>
      <tr>
        <td>2</td>
      </tr>
    </table>
    <table id="id3" style="display:block;">
      <tr>
        <td>3</td>
      </tr>
      <tr>
        <td>3</td>
      </tr>
      <tr>
        <td>3</td>
      </tr>
    </table>
    <table id="id4" style="display:block;">
      <tr>
        <td>4</td>
      </tr>
      <tr>
        <td>4</td>
      </tr>
      <tr>
        <td>4</td>
      </tr>
    </table>
    <table id="id5" style="display:block;">
      <tr>
        <td>5</td>
      </tr>
      <tr>
        <td>5</td>
      </tr>
      <tr>
        <td>5</td>
      </tr>
    </table>
    <table id="id6" style="display:block;">
      <tr>
        <td>6</td>
      </tr>
      <tr>
        <td>6</td>
      </tr>
      <tr>
        <td>6</td>
      </tr>
    </table>
    <table id="id7" style="display:block;">
      <tr>
        <td>7</td>
      </tr>
      <tr>
        <td>7</td>
      </tr>
      <tr>
        <td>7</td>
      </tr>
    </table>
  </body>
</html>

Edited 5 Years Ago by xml_looser: n/a

This article has been dead for over six months. Start a new discussion instead.