[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: default parameters

Subject: RE: default parameters
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Tue, 30 Jan 2001 21:47:16 -0000
xsl default parameter
> 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(
    count(node-set($months)/month[.=$date/month]::preceding-siblings)+1,
    '00')"/>
 <xsl:value-of select="format-number($date/day-of-month, '00')"/>
</xsl:template>

<xsl:variable name="months">
  <month>January</month>
  etc
</xsl:variable>

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

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

Then build a sorted list of dates:

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

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
trees.

>


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.