This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Number of node in list from stylesheet


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@epistemics.co.uk



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]