[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] given @id="1.2.3" .... -1 || +1 to the "3" in @id??


Subject: RE: [xsl] given @id="1.2.3" .... -1 || +1 to the "3" in @id??
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Mon, 2 Jul 2001 21:57:39 +0100

Anthony,
<xsl:value-of select="regExp:match(., '[0-9]+|\.', 'g')[5]" /> should do it.
Or
<xsl:value-of select="regExp:match(., '[0-9]+|\.',
'g')[count(regExp:match(., '[0-9]+|\.', 'g'))]" /> for any .00.00.00.00 Or
use tokenize
str:tokenize(., '.')

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


>-----Original Message-----
>From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Anthony E.
>Sent: 02 July 2001 20:14
>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>Subject: Re: [xsl] given @id="1.2.3" .... -1 || +1 to the "3" in @id??
>
>
>following-sibling:: would work if the elements were
>all in the same file, but our application requires
>they be in separate xml files.
>
>i will have a "first" & "last" attribute in my element
>that contains the id of those elements, so i can
>compare with current id w/ 'first' or 'last' to see if
>there should be a prev or next link.
>
>My main concern here is the syntax of getting the
>substring after the last '.' in a string: ie - if
>id="1.22.33" or "1.2.3", how do specify the character
>position of the last '.', since it will not always be
>the 4th or 5th character in the string.
>
>--
>Anthony
>
>--- Trevor Nash <tcn@xxxxxxxxxxxxx> wrote:
>> 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
>>
>
>
>__________________________________________________
>Do You Yahoo!?
>Get personalized email addresses from Yahoo! Mail
>http://personal.mail.yahoo.com/
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords