Subject: Re: [xsl] get value from link from last slash From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Wed, 14 Nov 2007 14:06:06 +0530 |
Please try this 1.0 stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:template match="/links"> <xsl:for-each select="link"> <xsl:variable name="result"> <xsl:call-template name="getImageName"> <xsl:with-param name="imgPath" select="." /> </xsl:call-template> </xsl:variable> <xsl:value-of select="$result" /><xsl:text>
</xsl:text> </xsl:for-each> </xsl:template> <xsl:template name="getImageName"> <xsl:param name="imgPath" /> <xsl:choose> <xsl:when test="contains($imgPath, '/')"> <xsl:call-template name="getImageName"> <xsl:with-param name="imgPath" select="substring-after($imgPath, '/')" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$imgPath" /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> The input XML is: <links> <link>root/statics/images/image.jpg</link> <link>root/images2/image2.jpg</link> </links> The output produced by the transform is: image.jpg image2.jpg The logic here mirrors Mike's idea. On Nov 14, 2007 1:25 PM, Vaduvoiu Tiberiu <vaduvoiutibi@xxxxxxxxx> wrote: > Hi, I have a little wierd problem. i have an xml where I have a bunch of image links like: > > root/statics/images/image.jpg > root/images2/image2.jpg > > is there a way to extract the names of the images using xslt 1.0? I need to extract the names of the images...image.jpg, image2.jp, etc. I thought about using substring but there are more than a slash in the path. Basically I would need the string from the last slash to the end. Sounds a little complicated but is there a way around it? 10x -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] get value from link from , Michael Kay | Thread | [xsl] XSL support of Bottom up tran, Raghu Narayan Korata |
RE: [xsl] get value from link from , Michael Kay | Date | Re: [xsl] Template matching precedi, Ilya Konanykhin |
Month |