Re: [xsl] A Counter Variable in XSLT?

Subject: Re: [xsl] A Counter Variable in XSLT?
From: Manu KY <manu_kry@xxxxxxxxx>
Date: Mon, 08 Oct 2001 09:35:10 +0530
Hi David,
please articulate your objective clearly :
what i can glean from the previous mails and this one is that you want to select all nodes which have a col attribute and then display them as an incremented serial number followed by the content of the attribute and the content of the node which matched.


Manu

What I want to do:

   My stylesheet consists of one template rule.  When there is a
   match, I want a line in the output  to say, for example, "Match #
   123:", followed by relevant text.  Since I don't know ahead of
   time how many matches there will be in the source document,
   somehow the stylesheet needs to keep a count.  Something like:

   <?xml version="1.0"?>
   <xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     <xsl:output method="text"/>
     <xsl:template match="/*">
           <xsl:if test="@col">
        Match # n : <!-- n is the nth match, the thing that needs to
   be incremented -->
        Collection: "<xsl:value-of select="@col"/>"
        Content: <xsl:value-of select="."/>
        </xsl:if>
     </xsl:template>
   </xsl:stylesheet>


how can n ever be anything other than 1 in this example. you are matching on /* and there is always exactly one element which is a child of the root of a well formed XML document. So it seems like n is 1 if that element has a col attribute and 0 otherwise, or your example was not representative of what you intended.

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

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


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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



Current Thread