+1 to the "3" in @id

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

Re: given @id="1.2.3" .... -1 || +1 to the "3" in @id

Subject: Re: given @id="1.2.3" .... -1 || +1 to the "3" in @id??
From: tcn@xxxxxxxxxxxxx (Trevor Nash)
Date: Sat, 30 Jun 2001 09:24:02 GMT
sat 1.2.3
There are two answers to this (at least ;-)

>given @id="1.2.3", how do I add or subtract 1 from the
>'.3' in the string "1.2.3" in a stylesheet?
>
>I need to create "prev | next" links generated from
>the current @id number for a file. ie - 'prev' link
>would be equal to '1.2.2', and 'next' link would be
>equal to '1.2.4'
>

The first is to point you at the substring() and concat() functions
(in XPath rather than XSLT, if you are working from the specs) which
you can use to rip the string apart, do the required arithmetic, and
glue it all back together again.  Conversion between numbers and
strings is usually implicit, though you can use string() and number()
if you need to or prefer to be explicit.  Yes, you can write Basic
programs in XSLT ;-))

Assuming you need to deal with id's of different lengths such as
23.4.874 or 1.2.3.4 you may need to look up recursive templates to
help you do the ripping apart.

The second answer is that you probably do not want to do it like this
at all.  How do you know that the next link for 1.2.3 is 1.2.4 and not
1.3 or 1.3.1 or even nothing at all?  It is much more likley that you
should be navigating to the next node within your XML document perhaps
using following:: or following-sibling:: then simply copying the @id
you find there.  This has the added benefit that it would still work
if your identifiers were like 1.2.a.  Without seeing your XML and
knowing whether you can change its design it is hard to advise
further.

Regards,
Trevor Nash

 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.