|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: not simple (or simple? :-) xpath matching
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
|
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








