Subject: [xsl] Re: not simple (or simple? :-) xpath matching From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Thu, 7 Jun 2001 11:09:37 -0700 (PDT) |
Jeni tennison wrote: > > Your example is made a little bit more complicated by the fact that > you want the 'nearest' chapter if there isn't an exact match. For the > nearest before, you want the last chapter whose @id is less than or > equal to the $chapter parameter, which makes the select expression: > > part[@id = $part]/chapter[@id <= $chapter][last()] > > For the nearest after, you want the first chapter whose @id is greater > than or equal to the value of the $chapter parameter, so the select > expression is: > > part[@id = $part]/chapter[@id >= $chapter][1] > Hi Daniel, I dont find the answer above satisfactory. Here's a better solution. What is actually needed is: min(abs($chapter - @id)) over the nodeset /document/part[@id = $part]/chapter This can be found very ellegantly using a common generic template finding a "generic minimum" node from a nodeset. You can read more about generic templates and template references at: http://sources.redhat.com/ml/xsl-list/2001-05/msg00276.html http://lists.fourthought.com/pipermail/exslt/2001-May/000169.html http://dpawson.co.uk/xsl/generic.html You can find several ellegant Xpath (sorry Jeni, not Javascript :)) ) expressions defining the abs() function here: http://www.vbxml.com/snippetcentral/main.asp?view=viewsnippet&lang=&id=v20010405003934 However, my favourite so far is one given by Sara ??? $num * (-($num < 0) + ($num > 0)) Hope this really helped. Cheers, Dimitre Novatchev. __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] A whitespace question, bu, Nice, Kerry A. (LNG- | Thread | [xsl] Re: not simple (or simple? :-, Daniel Bauke |
[xsl] Quark Express, Matt Gushee | Date | Re: [xsl] A whitespace question, bu, David Carlisle |
Month |