471,604 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,604 software developers and data experts.

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 5326
8,656 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)"/>
  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.

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
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>
  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> 
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
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.