Solved

Truncate text with XSLT

Posted on 2004-03-29
4
1,299 Views
Last Modified: 2012-06-27
Here is an XML fragment:

<stylist>
 <photo>thumb_image1.jpg</photo>
</stylist>


I need to be able to truncate the "thumb_" from the beginning of the string and append the rest of the string to an href.
as seen below:

<xsl:variable name="trimFileName">
    <xsl:value-of select="translate(photo,'thumb_','')" />
</xsl:variable>
                              
<a border="0" href="{$trimFileName}" target="_blank"><img src="{photo}" /></a>

The problem is that the translate function replaces any and all occurrences of the individual characters "t h u m b _".

Is there a function that allows me to just truncate a certain number of characters off of the string.  I have researched and there are (oddly enough) no trim functions.

Any suggestions appreciated.

robduke
0
Comment
Question by:robduke
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
dfiala13 earned 200 total points
ID: 10709008
there are three substring functions:

substring(string, startpos, [length])
substring-after(string1, string2)
substring-before(string1, string2)

<xsl:variable name="trimFileName">
    <xsl:value-of select="substring-after(photo, 'thumb_')" />
</xsl:variable>

will give you the string after thumb_
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10709016
here's a handy-dandy XSL tutorial that is a great reference...

http://nwalsh.com/docs/tutorials/xsl/xsl/slides.html
0
 

Author Comment

by:robduke
ID: 10709072
dfiala13,

I knew it was an easy fix!  I had seen plenty of examples of substring-before and after, but no documentation showing what they did.

Thank you very much! Exactly what i needed.  Thanks for the resource as well!

robduke
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10709083
You're welcome.  Glad to help.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question