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]

Re: Does XSL have arrays?


In message <200101040407.f0447xI10025@skew.org>, Mike Brown
<mike@skew.org> writes
>I would probably attempt it anyway, though. For example,
>if you just want the number of days in a given month (1-12),
>it would be something like this...
>
><xsl:variable name="month" select="6"/>
><xsl:variable name="days" select="number(substring('312831303130313130313031',$m
>onth * 2 - 1,2))"/>

How about using a chunk of XML as your 'array'?  Something like this:

<xsl:variable name="daysInMonth">
 <month n="1" days="31"/>
 <month n="2" days="28"/>
 <month n="3" days="31"/>
 <month n="4" days="30"/>
 <month n="5" days="31"/>
 <month n="6" days="30"/>
 <month n="7" days="31"/>
 <month n="8" days="31"/>
 <month n="9" days="30"/>
 <month n="10" days="31"/>
 <month n="11" days="30"/>
 <month n="12" days="31"/>
</xsl:variable>

<xsl:variable name="daysFromStartOfYear" select="sum(msxsl:node-
set($daysInMonth)/month[@n&lt;$month]/@days)+$day"/>

This assumes you have numeric variables $month and $day. It uses the
'node-set' extension function, but this is available in most XSLT
processors.

Richard Light.

Richard Light
SGML/XML and Museum Information Consultancy
richard@light.demon.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]