Tuesday, March 8, 2011

Get Reverse String in XSL


<xsl:template name="reverse">
<xsl:param name="theString"/>
<xsl:variable name="thisLength" select="string-length($theString)"/>
<xsl:choose>
<xsl:when test="$thisLength = 1">
<xsl:value-of select="$theString"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="restReverse">
<xsl:call-template name="reverse">
<xsl:with-param name="theString"
select="substring($theString, 1, $thisLength -1)"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of
select="concat(substring($theString,$thisLength, 1) ,$restReverse)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!--*****************Start Get File Name from URL *****************-->
<xsl:template name="GetFileName">
<xsl:param name="inputString"/>
<xsl:variable name="delimiter">/</xsl:variable>
<xsl:variable name="xxx">
<xsl:call-template name="reverse">
<xsl:with-param name="theString" select="$inputString" />
</xsl:call-template>
</xsl:variable>

<xsl:variable name="zzz">
<xsl:call-template name="reverse">
<xsl:with-param name="theString" select="substring-before($xxx,$delimiter)" />
</xsl:call-template>
</xsl:variable>

<xsl:value-of select="substring-before($zzz,'.')"/>
</xsl:template>
<!--*****************End Get File Name from URL *****************-->

No comments:

Post a Comment