[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] counter vs. functional counterpart


Subject: Re: [xsl] counter vs. functional counterpart
From: Ben Mendis <ben@xxxxxxxxxxxxxxxx>
Date: Tue, 21 Jul 2009 00:37:06 -0400

sorry, I didn't look closely enough at the example you gave...

<xsl:for-each select="/rows/row/*">
    <xsl:if test="count(text()) = 1">
        <xsl:value-of select="count(preceding::row/*/text()|preceding-sibling::*/text()) + 1"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>
</xsl:text>
    </xsl:if>
</xsl:for-each>

Regards,
Ben

Ben Mendis wrote:
> Hi Jeff,
> 
> Couldn't you use the XPATH count() function on the list of preceding
> siblings to determine your position in the list?
> 
>>From /rows/row
> <xsl:value-of select="count(preceding-sibling::*) + 1"/>
> should print out the position in the list.
> 
> Regards,
> Ben
> 
> Jeff Shelley wrote:
>> Hello.
>>    Does anybody know what xsl file can take this:
>>
>> <rows>
>>    <row>
>>        <name>John</name>
>>        <otherName/>
>>    </row>
>>    <row>
>>        <name>Paul</name>
>>        <otherName/>
>>    </row>
>>    <row>
>>        <name>Ringo</name>
>>        <nickName>ClassCastException</nickName>
>>    </row>
>>    <row>
>>        <name>George</name>
>>        <otherName/>
>>    </row>
>> </rows>
>>
>>
>> and turn it into this?
>>
>>     1-John
>>     2-Paul
>>     3-Ringo
>>     4-ClassCastException
>>     5-George
>>
>> Basically, I need the output number to keep incrementing and be
>> continuous.  Everything I see about counters says "if you're
>> implementing a counter you're doing it wrong", but I have absolutely
>> no idea how to do this.
>>
>> I'd appreciate any help.  Thanks!
>>
> 

-- 

Ben Mendis
Support Specialist
Antenna House
10410 Kensington Pkwy
Suite 207
Kensington, Maryland 20895
USA
Phone: +1 301-942-4007
Email: ben@xxxxxxxxxxxxxxxx
Web: www.antennahouse.com


Current Thread
Keywords