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

Number of node in list from stylesheet


Subject: Number of node in list from stylesheet
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Tue, 23 May 2000 12:24:41 +0100

Hi,

In answering Cheun Ngen CHONG's question about comparing dates, I ran into
a couple of problems that have left me puzzled (other one is in separate
email).

Within the stylesheet, I needed to convert a month's name into a month
number, so January = 01, May = 05 and so on.  So I defined the months in
order within the stylesheet itself:

<foo:months>
  <foo:month name="January" abbr="Jan" />
  <foo:month name="February" abbr="Feb" />
  ...
</foo:months>

Let's say that the month name is in a variable called $monthName.  How can
I assign a variable $monthNumber to the equivalent (two-digit) number?

I have tried xsl:number, but the count attribute cannot include the
document() function.

I have tried position(), but I don't know how, within a variable, to set
the context node list equal to the foo:month nodes and the context node
equal to the foo:month node with the desired name.  For example:

  <xsl:variable name="monthNumber">
    <xsl:for-each select="document('')//foo:month[@name = $monthName]">
      <xsl:value-of select="format-number(position(), '00')" />
    </xsl:for-each>
  </xsl:variable>

always sets $monthNumber = 1.

What am I missing?

Thanks for your help,

Jeni



Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email
jeni.tennison@xxxxxxxxxxxxxxxx



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



Current Thread