[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: not simple (or simple? :-) xpath matching

Subject: Re: not simple (or simple? :-) xpath matching
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 7 Jun 2001 11:09:37 -0700 (PDT)
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 &lt;= $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 &lt; 0) + ($num &gt; 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.