Hi all!
I'm about to create some dropdown boxes in a HTML page,
which contains months, and can be selected with an index
value in an xml file.
For example:
<monthrange>
<from>2</from>
<to>6</to>
</monthrange>
where from=2 should mean march, ad to=6 should mean july.
I'd like to create a callable template, with a parameter
given, which outputs an html fragment like this:
<option value="0">January</option>
<option value="1">February</option>
<option value="2" selected="1">March</option>
<option value="3">April</option>
.
.
.
<option value="11">December</option>
My question is, if there is an easy way to enumerate months
as predefined values, so I can create the callable template
something like this:
<xsl:for-each select="MONTHS">
<xsl:element name="option">
<xsl:attribute name="value"><xsl:value-of
select="position()-1" /></xsl:attribute>
<xsl:if test="number($selected)=position()-1">
<xsl:attribute name="selected">1</xsl:attribute>
</xsl:if>
<xsl:value-of select="NAME"/>
</xsl:element>
</xsl:for-each>
where $selected is the selected elements index, and NAME
should be (as I imagine) something like this:
<MONTHS>
<NAME>January</NAME>
<NAME>February</NAME>
.
.
.
<NAME>December</NAME>
</MONTHS>
I would really like to avoid listing all month options as
<xsl:element> declarations.
Best would be if the above could be declared in a separate
file, so I could call it from any stylesheets I use.
Probably it's an annoying question, as it must be
something obvious, but I could not find the way to solve this.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list