Solved

Truncate text with XSLT

Posted on 2004-03-29
4
1,306 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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