Subject: Re: [xsl]xpath for getting file version From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Thu, 16 Aug 2001 09:22:42 +0100 |
Hi Antony, >> Second, you could have a two-stage process (either with two >> stylesheets or using a node-set() extension function to do it all >> in one stylesheet). In the first pass, construct XML like the >> above, with a date attribute giving the entire date, and then use >> the XPath above in the key. > > If I use the second suggestion using the node-set() extension > function, how would I use the <xsl:key>? Say if I put my modified > XML into a variable called "temp". > > <xsl:variable name="modified" select="xalan:nodeset($temp)"/> > <xsl:key name="maxfile" match="$modified/person" > use="versions/version[not(@date < ../version/@date)]/@name"/> > > Is that how? Not quite. You use keys with generated node sets in the same way as you use keys with external documents. In other words, you need to set up the key at the top level of the stylesheet, making no reference to the document that the elements you're matching come from: <xsl:key name="maxfile" match="person" use="versions/version[not(@date < ../version/@date)]/@name"/> (BTW - should it really be matching 'person' elements there, not 'file' elements?) Then when you come to use the key, you need the current node to be in the generated node set. So you could do something like: <xsl:for-each select="$modified"> ... key('maxfile', $date) ... </xsl:for-each> But if you're copying everything into the new $modified node set then you may as well apply templates to that new node set, and treat it as if it was the original source, so you don't need to worry about wrapping xsl:for-eaches around the call to the key. Actually, thinking about it, I think you'd be better off creating a node set in which each file element had a 'latest' attribute holding the name of the latest version. You could set up the key on the value of that attribute: <xsl:key name="maxfile" match="file" use="@latest" /> This would leave you free to use whatever method you liked for calculating the latest date (a sort-and-select method, a recursive method, or using one of Dimitre's generic templates) rather than being stuck with the relatively inefficient XPath method that I suggested before. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl]xpath for getting file ver, Antony Suryadinata | Thread | RE: [xsl] Can i replace node by a v, Jarno . Elovirta |
Re: [xsl] getting XSL to output XSL, Aleksei Valikov | Date | Re: [xsl] getting XSL to output XSL, Jeni Tennison |
Month |