Subject: RE: [xsl] Taking string out from the long string From: Stuart Brown <sbrown@xxxxxxxxxxxxx> Date: Thu, 25 Jul 2002 12:58:07 +0100 |
Because substring-after extracts the substring after the *first* occurrence the slash, you must use a recursive template, passing the path as a parameter and extracting the substring-after each time until there are no slashes left: <!-- Match the img and call the named recursive template --> <xsl:template match="img"> <xsl:call-template name="getFilename"> <xsl:with-param name="currentString" select="@src"/> </xsl:call-template> </xsl:template> <!-- Named recursive template --> <xsl:template name="getFilename"> <xsl:param name="currentString"/> <xsl:choose> <xsl:when test="contains($currentString,'/')"> <!-- There are more folders to be removed, so recurse --> <xsl:call-template name="getFilename"> <xsl:with-param name="$currentString" select="substring-after($currentString,'/')"> </xsl:call-template> </xsl:when> <xsl:otherwise> <!-- Now you just have the file name, so output replacing the extension with wbmp --> <img src="{concat(substring-before($currentString,'.')),'.wbmp')}"/> </xsl:otherwise> </xsl:choose> </xsl:template> If there's a chance your filename may itself have more than one . in it, you'll have to recurse on that string as well. Hope this helps. Stuart > -----Original Message----- > From: ashu t [mailto:aashut@xxxxxxxxxxxxxx] > Sent: 25 July 2002 12:44 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Taking string out from the long string > > > i want to abstract just the file name from any image file > but not getting it correctly. > during conversion of html to wml when i am fetching the page i am > converting the .jif or .jpg or whatever image file into .wbmp > format and storing them in a folder. > and in <xsl:template match="img"> > what i want to do is that first i want to take the *src* of the > img tag in html file (which is now well formed xhtml as i am using > tidy to make them xhtml).which i think i can do by declaring a > variable and then variable = {@src}(i think it will work)then i > want to take the string after the last slash(/) in the src which > is the name of the image file (like src="dir/image.gif") this can > be done by string = substring-after(string, substring) but the > problem is that what to do if src is like /images/dir/image.gif > how can i tell that the string after the last slash is to be > taken. > and after that what i want to do is want to take the file name > before the extension like if file name is images.gif then i want > to take only images (which i think can be done by substring-before > then i want to add the extension .wbmp to that file (which i think > can be done by concat(images,.,wbmp) then i am creating an element > <img and in @src giving the path to my folder containing images as > they are saved with the same name just having extension .wbmp. > > how can i do it > ashu > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Taking string out from the lo, ashu t | Thread | RE: [xsl] Taking string out from th, Jarno . Elovirta |
[xsl] Taking string out from the lo, ashu t | Date | [xsl] Re: Taking string out from th, Dimitre Novatchev |
Month |