[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Becky,
Greg's solution is the best (cleanest and simplest). But if you can't use it, e.g. because you have to do other things with other elements inside your for-each but not inside your test, you can adapt xsl:number to do what you need:
You don't need to give xsl:number an explicit value here; its whole job is to number things.
At 02:05 PM 4/18/2002, you wrote:
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] incrementing a counter in XSL
Subject: Re: [xsl] incrementing a counter in XSL From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 18 Apr 2002 17:20:28 -0400 |
Becky,
Greg's solution is the best (cleanest and simplest). But if you can't use it, e.g. because you have to do other things with other elements inside your for-each but not inside your test, you can adapt xsl:number to do what you need:
<xsl:for-each select="Contract/TermRdr"> <xsl:if test="StatusCd='A' or StatusCd='F'"> <SequenceNum fieldType="Short" elementType="field"> <xsl:number count="TermRdr[StatusCd='A' or StatusCd='F']"/> </SequenceNum> .... </xsl:if> </xsl:for-each>
You don't need to give xsl:number an explicit value here; its whole job is to number things.
Cheers, Wendell
At 02:05 PM 4/18/2002, you wrote:
---------------------- Forwarded by Becky Foley/IIG/Prudential on 04/18/2002 02:05 PM --------------------------- Becky Foley Thursday April 18, 2002 12:13 PM (973) 802-6567 To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx cc: Subject: incrementing a counter in XSL
I am selecting some nodes from an XML doc with an if statment in a for-each loop. Out of the set of nodes I am looping through, I am only selecting some in the if statment. Each of these nodes that is selected by the if statement needs a sequence number. Originally I was using : <xsl:for-each select="Contract/TermRdr"> <xsl:if test="StatusCd='A' or StatusCd='F'"> <SequenceNum fieldType="Short" elementType ="field"><xsl:number value ="position()"/></SequenceNum> .... </xsl:if> </xsl:for-each>
but I realized I was getting the position from the source xml. So if the if statement selected 2 of the 5 nodes, they could end up with sequence numbers 2 and 4 as opposed to the 1 and 2 I am looking for.
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] incrementing a counter in, Greg Faron | Thread | Re: [xsl] incrementing a counter in, becky . foley |
Re: [xsl] Comparing an attribute va, Joerg Heinicke | Date | Re: [xsl] Schema Exploration..., Wendell Piez |
Month |
Keywords