469,282 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

XST String Reverse

I have a string value in a node of a xml file.
For example:a/b/c/d.
By using XSLT i need to chane the string in a reverse order.
For Example: d/c/b/a.
How to do this please help its urgent.
Oct 23 '08 #1
3 5143
Dormilich
8,651 Expert Mod 8TB
after a while of thinking, this came to my mind:
Expand|Select|Wrap|Line Numbers
  1. // <xsl:param name="input" select="--get-text-here--"/>
  2. <xsl:param name="result"></xsl:param>
  3. <xsl:param name="pos" select="string-length($input)"/>
  4.  
  5. <xsl:template name="xyz">
  6.   <xsl:param name="result" select="concat($result, substring($input, $pos, 1))"/>
  7.   <xsl:param name="pos" select="$pos - 1"/>
  8.   <xsl:if test="$pos gt; 0">
  9.     <xsl:call-template name="xyz"/>
  10.   </xsl:if>
  11. </xsl:template>
I didn't check it (had no time), maybe you have to use <xsl:with-param>. at least this should get you started.

regards
Oct 23 '08 #2
I have tried out the code it is not working can u check and send me the working code again please it is urgent.
Oct 24 '08 #3
jkmyoung
2,057 Expert 2GB
Reduce the string one letter at a time. Then output from the back. As the template calls come back, the string will start outputting from the back first.
Expand|Select|Wrap|Line Numbers
  1. <xsl:call-template name="xyz">
  2.   <xsl:with-param name="input" select="."/><!-- change xpath here -->
  3. </xsl:call-template>
  4.  
  5.  
  6. <xsl:template name="xyz"> 
  7.   <xsl:param name="input"/>
  8.   <xsl:if test="string-length($input) &gt; 0">
  9.     <xsl:call-template name="xyz"> 
  10.       <xsl:with-param name="input" select="substring($input, 2)"/>
  11.     </xsl:call-template>
  12.     <xsl:value-of select="substring($input, 1, 1)">
  13.   </xsl:if>
  14. </xsl:template> 
  15.  
Oct 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

24 posts views Thread by ineedyourluvin1 | last post: by
24 posts views Thread by Sathyaish | last post: by
47 posts views Thread by sudharsan | last post: by
2 posts views Thread by Kelly B | last post: by
15 posts views Thread by rajash | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.