RE: [xsl] default parameters

Subject: RE: [xsl] default parameters
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Tue, 30 Jan 2001 21:47:16 -0000
> Does anyone know how to set the default value of a parameter
> to an attribute
> value, like an id, from an element whose date attribute is
> the most recent
> out of all similar date attributes?

It can be done, but it isn't easy, especially if you want to avoid the
node-set() extension.

Firstly, a named template that converts your date to a sortable string,
something like

<xsl:template name="iso-date">
 <xsl:param name="date"/>
 <xsl:value-of select="format-number($date/year, '0000')"/>
 <xsl:value-of select="format-number(
 <xsl:value-of select="format-number($date/day-of-month, '00')"/>

<xsl:variable name="months">

Then build a list of iso dates in a global variable:

<xsl:variable name="all-dates">
  <xsl:for-each select="//date">
      <xsl:call-template name="iso-date">
         <xsl:with-param name="date" select="."/>

Then build a sorted list of dates:

<xsl:variable name="sorted-dates">
  <xsl:for-each select="node-set($all-dates)/iso-date">
     <xsl:copy-of select="."/>

Then choose the first one in this list:

<xsl:param name="date" select="node-set($sorted-dates)/iso-date[1]"/>

Mike Kay

I forgot that you wanted the default to be not the date, but some other
derived value: you will have to carry that value around on the constructed


 XSL-List info and archive:

Current Thread