|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: default parameters
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








