This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: lastIndexOf('char') and XSLT string functions
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] lastIndexOf('char') and XSLT string functions
- From: Troadec Pascal <Pascal dot Troadec at srit dot siemens dot fr>
- Date: Thu, 15 Feb 2001 16:13:03 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Jeni,
thank you for your solution. it is a great help for me.
it is a good way to do what i want.
thanks again
pascal
> -----Original Message-----
> From: Jeni Tennison
> Sent: Donnerstag, 15. Februar 2001 10:59
> To: Troadec Pascal
> Cc: 'XSL-List@lists.mulberrytech.com'
> Subject: Re: [xsl] lastIndexOf('char') and XSLT string functions
>
> Hi Troadec,
>
> > i'm looking for a xslt method to identify the last iteration of a
> > char into a string. For example, to extract automatically the name
> > of the html page into the url.
> >
> > string : "h ttp://www.thesite.com/directory1/dir2/dir3../pageindex.htm"
> >
> > there are the functions substrings-before() et substring-after(),
> > but they work on the first occurence of the marker-string. Is there
> > a Xslt function which gives the last occurence of a marker-string
> > (like lastIndexOf('/',"string")) into a string?
>
> No, there isn't.
>
> You can achieve what you want through recursion. Walk through the
> string, taking bits off the front of it until you get to a string
> which has no '/' in it whatsoever.
>
> <!-- define a lastIndexOf named template -->
> <xsl:template name="lastIndexOf">
> <!-- declare that it takes two parameters - the string and the char -->
> <xsl:param name="string" />
> <xsl:param name="char" />
> <xsl:choose>
> <!-- if the string contains the character... -->
> <xsl:when test="contains($string, $char)">
> <!-- call the template recursively... -->
> <xsl:call-template name="lastIndexOf">
> <!-- with the string being the string after the character
> -->
> <xsl:with-param name="string"
> select="substring-after($string, $char)" />
> <!-- and the character being the same as before -->
> <xsl:with-param name="char" select="$char" />
> </xsl:call-template>
> </xsl:when>
> <!-- otherwise, return the value of the string -->
> <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> To get the filename of a URL held in the URL child of the current
> node, you can call this template like:
>
> <xsl:call-template name="lastIndexOf">
> <xsl:with-param name="string" select="URL" />
> <xsl:with-param name="char" select="/" />
> </xsl:call-template>
>
> It's pretty verbose, but I'm afraid that's the only way to do it in
> XSLT at the moment.
>
> I hope that helps,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.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