Re: [xsl] Position or Count

Subject: Re: [xsl] Position or Count
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 31 Oct 2001 18:38:20 +0000
Hi Kevin,

> What I am trying to do is print the position number with a comma
> until it is the last number which will then only print the number.
> This has been easy enough in the past but I have a new wrinkle in my
> code. With <xsl:if test="$layerExistence2 ='TRUE'"> only some layers
> pass the test. So the result is mass confusion (on my part) for the
> $Position variable determining if it is the last element or not. I
> only want it to use elements that pass the test to determine
> position.

I'm not sure if I'm following the code correctly, but it looks as if
you're trying to print the position of the layer_params element
amongst other layer_params elements in the document, but only for
certain of those layer_params elements.

The easiest way to do something to all but the last of a list is to
iterate over the list in order and pick out the last one. To do this,
you need to be interested in all the items in the list. So what about
only selecting those layer_params elements that fulfil the condition,
and using xsl:number to number them? Something like:

  <xsl:for-each
    select="//layer_params
              [key('state-lookup',
                   substring-after(../data_params/data_description_params
                                     /properties/property/@value,
                                   '&#xA;'))/EXIST = 'TRUE']">
    <xsl:number level="any" />
    <xsl:if test="position() != last()">,</xsl:if>
  </xsl:for-each>

This won't work if the call to the 'state-lookup' key has to occur in
the document holding the ROWSET elements rather than the document
holding the layer_params element. If that's the case, I suggest always
generating the comma, and then stripping the comma from the resulting
string using the substring() function.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread