How to get the path last element using xslt

Here should go questions about transforming XML with XSLT and FOP.
shiney_98
Posts: 12
Joined: Thu Sep 09, 2021 12:03 pm

How to get the path last element using xslt

Post by shiney_98 »

Hi,
I have a param in xslt . For Example, <xsl:param name="filePath"/>

The filepath is something like C:\xml\inwork\bookmap\preview\lessonName
I need to print exactly the lessonName in the attribute value.

I tried using <substring-after($filePath, '/')[last[])"/>
and <substring-after((tokenize($filePath, '/')[last[])"/> , but it is not working

Any possible solutions?
xephon
Posts: 134
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: How to get the path last element using xslt

Post by xephon »

You have to tokenize the path based on the separator.
stefan-jung.org – Your DITA/DITA-OT XML consultant
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to get the path last element using xslt

Post by Radu »

Hi,

Also use the XSLT tokenize function as "substring-after" returns the first occurrence of the match.
Something like:

Code: Select all

<xsl:value-of select="tokenize($filePath, '\\')[last()]"/>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
shiney_98
Posts: 12
Joined: Thu Sep 09, 2021 12:03 pm

Re: How to get the path last element using xslt

Post by shiney_98 »

Thank u Radu
Post Reply