RE: Reverse Tokens Template
Hi. Try this template: <xsl:template name="reverse"> <xsl:param name="str" select="string(.)"/> <xsl:param name="res" select="''"/> <xsl:param name="sep" select="''"/> <xsl:choose> <xsl:when test="contains($str,' ')"> <xsl:call-template name="reverse"> <xsl:with-param name="str" select="substring-after($str,' ')"/> <xsl:with-param name="sep" select="' '"/> <xsl:with-param name="res" select="concat(substring-before($str,' '),$sep,$res)"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat($str,$sep,$res)"/> </xsl:otherwise> </xsl:choose> </xsl:template> It recursively breaks the string on the space char and concat each peace backwardly. Hope that this helps you Américo Albuquerque > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Greene, Stephen > Sent: Thursday, May 15, 2003 3:39 PM > To: XSL List (E-mail) > Subject: Reverse Tokens Template > > > Hi, > > I have been trying to modify (un-sucessfully) Dimitre > Novatchev's template to reverse the order of "words" in a > string (words being character substrings seperated by a space > character). Such that the string "hello world" would become > "world hello". I was wondering if anyone would be able to > offer any hints on how to accomplish this. > > I have tried modifying the template but as the word length is > variable, (and the words need to go back into a string, and > not be output) I have been unsuccessful in concatenating the > string after removing one word at a time. > > If this is not possible, is there a way in which I could > remove one word at a time from the end of the string? (in a > substring-before($theString, ' ') like way) Instead of the beginning? > > I thank you for your time and for your help, > > Regards, > > Stephen Greene > > National Research Council of Canada > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format