Re: [xsl] How to determine the 'first' time a template has been

Subject: Re: [xsl] How to determine the 'first' time a template has been
From: Dan Diebolt <dandiebolt@xxxxxxxxx>
Date: Tue, 20 Mar 2001 07:05:53 -0800 (PST)
call-template does not support a mode attribute. I am a bit hard 
pressed to understand why you would need to detect the first use of 
call-template - especially if your are using it within xsl-variable. 

In my usage of XSLT, I often have to do something before 
processing the first node of a node set (kick out introductory 
text or a table header) or perhaps with the first/last node itself. 
You can flag the first node in a node set by several methods:

File: FirstTimeTemplateCalled.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="FirstTimeTemplateCalled.xsl"?>
<root>
 <item>10</item>
 <item>20</item>
 <item>30</item>
</root>

file: FirstTimeTemplateCalled.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:template match="/">
  <xsl:apply-templates select="root"/>
 </xsl:template>
 <xsl:template match="root">
  start processing items.<br/>
  <xsl:apply-templates select="item"/>
  end processing items.<br/>
 </xsl:template>
 <xsl:template match="item">
  <xsl:variable name="i1"><xsl:number/></xsl:variable>
  <xsl:variable name="i2" select="position()"/>
  i1=<xsl:value-of select="$i1"/>
  i2=<xsl:value-of select="$i2"/>
  <xsl:if test="$i1=1">- i1=1 indicates first element</xsl:if>
  <xsl:if test="$i2=1">- i2=1 indicates first element</xsl:if>
  <br/>
 </xsl:template>
</xsl:stylesheet>
      





__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread