Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Deleteing all characters in a string until certain character....

Question posted by: tytyguy (Newbie) on June 28th, 2008 05:11 AM
Ok so I have an xml file that list image urls like this....

Code: ( text )
  1. <imageurl>http://www.tirerack.com/images/tires/kumho/ku_victoracer_s.jpg</imageurl>


I would like to be able to use xslt to transform it to this....

Code: ( text )
  1. <imageurl>ku_victoracer_s.jpg</imageurl>


I tried using a substring, but it just removes it from the first slash, and since the url has a couple slashes in i, that doesnt work. How can I do this?
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
jkmyoung's Avatar
jkmyoung
Moderator
765 Posts
July 2nd, 2008
06:24 PM
#2

Re: Deleteing all characters in a string until certain character....
Should be something like this recursive template.
Code: ( text )
  1. <xsl:template match="imageurl">
  2. <xsl:copy>
  3.        <xsl:call-template name="removeUntilLast">
  4.          <xsl:with-param name="str" select="."/>
  5.          <xsl:with-param name="searchStr" select="'/'"/>
  6.        </xsl:call-template>
  7. </xsl:copy>
  8. </xsl:template>
  9.  
  10. <xsl:template name="removeUntilLast">
  11.    <xsl:param name="str"/>
  12.    <xsl:param name="searchStr" select="'/'"/> <!-- cannot be blank -->
  13.    <xsl:choose>
  14.      <xsl:when test="contains($str, $searchStr))">
  15.        <xsl:call-template name="removeUntilLast">
  16.          <xsl:with-param name="str" select="substring-after($str, $searchStr)"/>
  17.          <xsl:with-param name="searchStr" select="$searchStr"/>
  18.        </xsl:call-template>
  19.      </xsl:when>
  20.      <xsl:otherwise><xsl:value-of select="$str"/></xsl:otherwise>
  21.    </xsl:choose>
  22. </xsl:template>

Reply
Reply
Not the answer you were looking for? Post your question . . .
182,494 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top XML Forum Contributors