How to get last value in delimited string?

B

bearclaws

I'm new to XML/XSL and need to get the last value from a string that
looks like this (where the colon is the delimiter)...

Computers:Drives:Firewire:Hard Drive

I have an XSL file that gets this whole string passed to it as a
variable, but I just want to write "Hard Drive" to the screen.
Any suggestions?

Thanks,
BC
 
J

Joris Gillis

Tempore 19:00:10 said:
Computers:Drives:Firewire:Hard Drive

I have an XSL file that gets this whole string passed to it as a
variable, but I just want to write "Hard Drive" to the screen.
Any suggestions?
Hi,

this is an XSLT1.0 solution:

<xsl:template name="tail">
<xsl:param name="string" select="."/>
<xsl:choose>
<xsl:when test="substring-after($string,':')">
<xsl:call-template name="tail">
<xsl:with-param name="string" select="substring-after($string,':')"/>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$string"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>call the template with e.g.:

<xsl:call-template name="tail">
<xsl:with-param name="string" select="$variable"/>
</xsl:call-template>

(by default, it will select the string value of the context node)

regards,
 
B

bearclaws

This worked perfectly :)

Can you recommend any sites or books that will help me learn more about
XSLT (i.e. with examples like the one you provided)?
Many thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top