Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Truncate text with XSLT

Posted on 2004-03-29
4
Medium Priority
?
1,318 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 800 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

Technology Partners: 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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2

971 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