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( 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] default parameters, Brian Killian | Thread | [xsl] FOP: how do I get my content , Pouliot, Brian R. |
[xsl] Numbering Grouped Child Eleme, Jake Stevenson | Date | RE: [xsl] Using XSLT parameters wit, Bowen, Randy |
Month |