Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl:variable increment 1

Status
Not open for further replies.

CassidyHunt

IS-IT--Management
Jan 7, 2004
688
0
0
US
I need to setup an element to print before every row except for the first row.

in visual basic I would do it like this:
Code:
dim i as integer

i = 0
for each sitem in ar
if i > 0 then
    'Handle somethign here

else
    i = i + 1
end if

'do something here
next

Thanks

Cassidy
 
You would use the position() function which returns the position of the nodes being processed.

So it would be something like:

<xsl:apply-templates select="NODE_NAME[not(position()=1)]" />
 
Cassidy,

Better would be to post what the input (probably simplified but still illustrative) would be and the desired results. Then we will be doing a lot less guessing. [ponder]

Tom Morrison
 
Its hard to actually post the data because it is a huge file. 10,000 + records. here is the XSLT

Code:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:output method="html"/>
<xsl:variable name="counter">0</xsl:variable>
<xsl:template match="/">
	<xsl:apply-templates />
</xsl:template>

<xsl:template match="//Dispatch/Resource">
	<div id="{RESOURCE_ID}" class="jobs">
	<xsl:apply-templates select="//Dispatch/Operation">
		<xsl:with-param name="resourceid" select="RESOURCE_ID" />
		<xsl:with-param name="desc" select="DESCRIPTION" />
	</xsl:apply-templates>
	</div>
</xsl:template>

<xsl:template match="//Dispatch/Operation">
	<xsl:param name="resourceid" />
	<xsl:param name="desc" />
<xsl:if test="RESOURCE_ID = $resourceid">

	<p class='pagebreakhere'></p>
	<table width="600">
		<caption>
			<table>
				<tr>
					<td>#<xsl:value-of select="WORKORDER_BASE_ID"/></td>
					<td><xsl:value-of select="WORKORDER_LOT_ID"/></td>
					<td><xsl:value-of select="WORKORDER_SPLIT_ID"/></td>
					<td><xsl:value-of select="WORKORDER_SUB_ID"/></td>
					<td><xsl:value-of select="CUSTOMER_NAME"/></td>
				</tr>
			</table>
		</caption>
		<tbody>
			<tr>
				<td>
					<table class="heading">
						<thead>
							<tr>
								<th>Resource ID</th>
								<th>Resource Description</th>
								<th>Start Date</th>
								<th>Finish Date</th>
								<th>Setup</th>
								<th>Run</th>
								<th>Reported Hours</th>
								<th>Remaining Hours</th>
								<th>Qty</th>
								<th>Completed Qty</th>
								<th>Remaining Qty</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td><xsl:value-of select="$resourceid"/></td>
								<td><xsl:value-of select="$desc"/></td>
								<td><xsl:call-template name="formatDate">
										<xsl:with-param name="given" select="START_DATE" />
									</xsl:call-template>
								<!--<xsl:value-of select="START_DATE"/>!--></td>
								<td><xsl:call-template name="formatDate">
										<xsl:with-param name="given" select="FINISH_DATE" />
									</xsl:call-template>
									<!--<xsl:value-of select="FINISH_DATE"/>!--></td>
								<td><xsl:value-of select="SETUP_HRS"/></td>
								<td><xsl:value-of select="RUN_HRS"/></td>
								<td><xsl:value-of select="ACT_SETUP_HRS + ACT_RUN_HRS" /></td>
								<td><xsl:value-of select='format-number(((SETUP_HRS + RUN_HRS) -(ACT_SETUP_HRS + ACT_RUN_HRS)),"#.00")' /></td>
								<td><xsl:value-of select="CALC_START_QTY"/></td>
								<td><xsl:value-of select="COMPLETED_QTY"/></td>
								<td>
								<xsl:value-of select='format-number((CALC_START_QTY - COMPLETED_QTY),"#.00")' /></td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<thead>
							<tr>
								<th>Workorder ID</th>
								<th>Part ID - Description</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td><xsl:value-of select="WORKORDER_BASE_ID"/>-<xsl:value-of select="WORKORDER_LOT_ID"/>/<xsl:value-of select="WORKORDER_SUB_ID"/></td>
								<td>PART ID - Description</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<tbody>
							<tr>
								<th>Engineered By:</th><td><xsl:value-of select="WORKORDER_ENGINEERED_BY"/></td>
								<th>Operation Seq:</th><td><xsl:value-of select="SEQUENCE_NO"/></td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<tr>
							<th valign="top">Description:</th>
							<td><xsl:value-of select="OPERATION_SPEC"/></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<tr>
							<td class="barcode">*%2<xsl:value-of select="WORKORDER_BASE_ID"/>$<xsl:value-of select="WORKORDER_LOT_ID"/>$<xsl:value-of select="WORKORDER_SPLIT_ID"/>$<xsl:value-of select="WORKORDER_SUB_ID"/>$<xsl:value-of select="SEQUENCE_NO"/>%*</td>
							<td>
								<table>
									<tr>
										<th>Prev OP:</th><td>RES</td><th>Qty:</th><td>1</td>
									</tr>
									<tr>
										<th>Next:</th><td colspan="3">RES</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					Quality Op Inspection done?&#160;&#160;&#160;Yes&#160;&#160;No<br /><br />
						Inspected by:_____________________________&#160;Date:___________&#160;Double checked by:__________________________<br />
						(Be sure to document Inspection on this dispatch, the print/sketch or an inspection form.)
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<thead>
							<tr>
								<th>Main Resource</th>
								<th>Concurrent Resource(s)</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td><xsl:value-of select="MAIN_RESOURCE"/></td>
								<td><xsl:value-of select="CONCURRENT"/></td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
		</tbody>
	</table>		
	<hr />
	<xsl:apply-templates select="//Dispatch/Requirement">
		<xsl:with-param name="scheduleid" select="SCHEDULE_ID" />
		<xsl:with-param name="workordertype" select="WORKORDER_TYPE" />
		<xsl:with-param name="workorderbaseid" select="WORKORDER_BASE_ID" />
		<xsl:with-param name="workorderlotid" select="WORKORDER_LOT_ID" />
		<xsl:with-param name="workordersplitid" select="WORKORDER_SPLIT_ID" />
		<xsl:with-param name="workordersubid" select="WORKORDER_SUB_ID" />
		<xsl:with-param name="sequenceno" select="SEQUENCE_NO" />
	</xsl:apply-templates>
	</xsl:if>
</xsl:template>

<xsl:template match="//Dispatch/Requirement">
    <xsl:param name="scheduleid" />
	<xsl:param name="workordertype" />
	<xsl:param name="workorderbaseid" />
	<xsl:param name="workorderlotid" />
	<xsl:param name="workordersplitid" />
	<xsl:param name="workordersubid" />
	<xsl:param name="sequenceno" />
    <xsl:if test="SCHEDULE_ID = $scheduleid">
		<xsl:if test="WORKORDER_TYPE = $workordertype">
			<xsl:if test="WORKORDER_BASE_ID = $workorderbaseid">
				<xsl:if test="WORKORDER_LOT_ID = $workorderlotid">
					<xsl:if test="WORKORDER_SPLIT_ID = $workordersplitid">
						<xsl:if test="WORKORDER_SUB_ID = $workordersubid">
							<xsl:if test="SEQUENCE_NO = $sequenceno">
								<table width="600px" calss="heading">
									<thead>
										<tr>
											<th>Req Part ID</th>
											<th>Piece No</th>
											<th>Qty Required</th>
											<th>Issued Qty</th>
											<th>Whs ID</th>
											<th>Whs Qty</th>
										</tr>
									</thead>
									<tbody>
										<tr align="center">
											<td><xsl:value-of select="PART_ID"/></td>
											<td><xsl:value-of select="PIECE_NO"/></td>
											<td><xsl:value-of select="CALC_QTY"/></td>
											<td><xsl:value-of select="ISSUED_QTY"/></td>
											<td><xsl:value-of select="PRIMARY_WHS_ID"/></td>
											<td><xsl:value-of select="QTY_ON_HAND"/></td>
										</tr>
									</tbody>
									<tfoot>
										<tr>
											<td colspan="5" class="barcode" width="85%">*%2<xsl:value-of select="WORKORDER_BASE_ID"/>$<xsl:value-of select="WORKORDER_LOT_ID"/>$<xsl:value-of select="WORKORDER_SPLIT_ID"/>$<xsl:value-of select="WORKORDER_SUB_ID"/>$<xsl:value-of select="SEQUENCE_NO"/>$<xsl:value-of select="PIECE_NO"/>%*</td>
											<td><xsl:value-of select="DESCRIPTION"/></td>
										</tr>
										<tr>
											<td colspan="6"><xsl:value-of select="REQUIREMENT_SPEC"/></td>
										</tr>
									</tfoot>
								</table>
								<hr />

							</xsl:if>
						</xsl:if>
					</xsl:if>
				</xsl:if>
			</xsl:if>		
		</xsl:if>
    </xsl:if>

	
</xsl:template>

<xsl:template name="formatDate">
<!-- variable name: given, alias x -->
<xsl:param name="given"/>
<xsl:variable name="y" select="substring-before($given,'T')" />
<xsl:variable name="CCYY" select="substring-before($y,'-')" />
<xsl:variable name="tmp" select="substring-after($y,'-')" />
<xsl:variable name="MM" select="substring-before($tmp,'-')" />
<xsl:variable name="DD" select="substring-after($tmp,'-')" />
<xsl:variable name="z" select="substring-after($given,'T')" />
<xsl:variable name="hh" select="substring-before($z,':')" />
<xsl:variable name="tmp2" select="substring-after($z,':')" />
<xsl:variable name="mm" select="substring-before($tmp2,':')" />
<xsl:variable name="tmp3" select="substring-after($tmp2,':')" />
<xsl:variable name="hh_norm">
    <xsl:choose>
        <xsl:when test="$hh &gt; 12">
            <xsl:value-of select="$hh - 12" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$hh" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>
<xsl:variable name="sffx">
    <xsl:choose>
        <xsl:when test="$hh &gt; 12">
            <xsl:value-of select="'pm'" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="'am'" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>
<xsl:variable name="mm_norm" select="$mm" />
<xsl:variable name="result" select="concat($MM,'/',$DD,'/',$CCYY,' ',$hh_norm,':',$mm_norm,' ',$sffx)" />
<!-- display result here -->
<xsl:value-of select="$result" />
</xsl:template>

</xsl:stylesheet>

You will see part ways down in the template a tag:

Code:
<p class='pagebreakhere'></p>

My Goal with this post is that the first time the template encounters this tag it ignores. Only the first time.

The other piece that I am lacking to being complete with this project is to be able to perform a left join within the document and filter results based on something similiar to a where clause. That would probably be another post.

Thanks

Cassidy
 
As I said - try using the position() function.

<xsl:if test="not(position()=1)">
<p class='pagebreakhere'></p>
</xsl:if>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top