Solved

Truncate text with XSLT

Posted on 2004-03-29
4
1,311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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, …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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