Last post Jan 09, 2013 10:59 AM by mkonanki
Participant
1637 Points
688 Posts
Jan 08, 2013 07:22 AM|mkonanki|LINK
Hi
I have as xml strings like below
1. M:Namespace.Class.Method(Class.Method1 , Class.Method2)
2. M:Namespace.Class.Method(m.Class.Method1 )
need output like below
2. Method(Method1 ).
how to write xslt for above scenario could you any body suggest.
Jan 09, 2013 10:59 AM|mkonanki|LINK
I got solution.
<xsl:template name="substring-after-last"> <xsl:param name="string" /> <xsl:param name="delimiter" /> <xsl:choose> <xsl:when test="contains($string, $delimiter)"> <xsl:call-template name="substring-after-last"> <xsl:with-param name="string" select="substring-after($string, $delimiter)" /> <xsl:with-param name="delimiter" select="$delimiter" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string" /> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template name="substringXSLT"> <xsl:param name="string" /> <xsl:choose> <xsl:when test="($string[contains(., '(')])"> <xsl:variable name="string1" select="substring-before($string, '(')" /> <xsl:variable name="string2" select="substring-after($string, '(')" /> <!--<xsl:value-of select="$string" /> <xsl:value-of select="' '" />--> <xsl:call-template name="substring-after-last"> <xsl:with-param name="string" select="$string1" /> <xsl:with-param name="delimiter" select="'.'" /> </xsl:call-template> <xsl:value-of select="'('" /> <xsl:variable name="Substring" select="substring-after($string2, '{')" /> <xsl:choose> <xsl:when test="$Substring != ''"> <xsl:variable name="string4" select="substring-before(substring-after($string2, '{'),'}')" /> <xsl:call-template name="substring-after-last"> <xsl:with-param name="string" select="$string4" /> <xsl:with-param name="delimiter" select="'.'" /> </xsl:call-template> <xsl:value-of select="')'" /> </xsl:when> <xsl:otherwise> <xsl:variable name="Commastring" select="substring-before($string2, ',')" /> <xsl:choose> <xsl:when test="$Commastring != ''"> <!--<xsl:variable name="string5" select="substring-before($Commastring, ',')" />--> <xsl:call-template name="substring-after-last"> <xsl:with-param name="string" select="$Commastring" /> <xsl:with-param name="delimiter" select="'.'" /> </xsl:call-template> <xsl:value-of select="','" />
<xsl:variable name="string6" select="substring-after($string2, ',')" /> <xsl:call-template name="substring-after-last"> <xsl:with-param name="string" select="$string6" /> <xsl:with-param name="delimiter" select="'.'" /> </xsl:call-template> <xsl:value-of select="')'" /> </xsl:when> <xsl:otherwise> <xsl:call-template name="substring-after-last"> <xsl:with-param name="string" select="$string2" /> <xsl:with-param name="delimiter" select="'.'" /> </xsl:call-template> <xsl:value-of select="')'" /> </xsl:otherwise>
</xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:call-template name="substring-after-last"> <xsl:with-param name="string" select="$string" /> <xsl:with-param name="delimiter" select="'.'" /> </xsl:call-template> </xsl:otherwise> </xsl:choose>
</xsl:template>
input -----------------
<xsl:call-template name="substringXSLT"> <xsl:with-param name="string" select="@name" />
</xsl:call-template>
Participant
1637 Points
688 Posts
Getting a substring AFTER the last occurrence of a character in XSLT
Jan 08, 2013 07:22 AM|mkonanki|LINK
Hi
I have as xml strings like below
1. M:Namespace.Class.Method(Class.Method1 , Class.Method2)
2. M:Namespace.Class.Method(m.Class.Method1 )
need output like below
2. Method(Method1 ).
how to write xslt for above scenario could you any body suggest.
Participant
1637 Points
688 Posts
Re: Getting a substring AFTER the last occurrence of a character in XSLT
Jan 09, 2013 10:59 AM|mkonanki|LINK
I got solution.
<xsl:template name="substring-after-last">
<xsl:param name="string" />
<xsl:param name="delimiter" />
<xsl:choose>
<xsl:when test="contains($string, $delimiter)">
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string"
select="substring-after($string, $delimiter)" />
<xsl:with-param name="delimiter" select="$delimiter" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="substringXSLT">
<xsl:param name="string" />
<xsl:choose>
<xsl:when test="($string[contains(., '(')])">
<xsl:variable name="string1" select="substring-before($string, '(')" />
<xsl:variable name="string2" select="substring-after($string, '(')" />
<!--<xsl:value-of select="$string" />
<xsl:value-of select="' '" />-->
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="$string1" />
<xsl:with-param name="delimiter" select="'.'" />
</xsl:call-template>
<xsl:value-of select="'('" />
<xsl:variable name="Substring" select="substring-after($string2, '{')" />
<xsl:choose>
<xsl:when test="$Substring != ''">
<xsl:variable name="string4" select="substring-before(substring-after($string2, '{'),'}')" />
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="$string4" />
<xsl:with-param name="delimiter" select="'.'" />
</xsl:call-template>
<xsl:value-of select="')'" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="Commastring" select="substring-before($string2, ',')" />
<xsl:choose>
<xsl:when test="$Commastring != ''">
<!--<xsl:variable name="string5" select="substring-before($Commastring, ',')" />-->
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="$Commastring" />
<xsl:with-param name="delimiter" select="'.'" />
</xsl:call-template>
<xsl:value-of select="','" />
<xsl:variable name="string6" select="substring-after($string2, ',')" />
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="$string6" />
<xsl:with-param name="delimiter" select="'.'" />
</xsl:call-template>
<xsl:value-of select="')'" />
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="$string2" />
<xsl:with-param name="delimiter" select="'.'" />
</xsl:call-template>
<xsl:value-of select="')'" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="$string" />
<xsl:with-param name="delimiter" select="'.'" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
input
-----------------
<xsl:call-template name="substringXSLT">
<xsl:with-param name="string" select="@name" />
</xsl:call-template>