Solved

Truncate text with XSLT

Posted on 2004-03-29
4
1,295 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You're welcome.  Glad to help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Building a string from an xml 6 85
XSLT Assistance 9 44
How do I bind the results to a grid 3 22
Word files to Wordpress Posts 2 22
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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, …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now