[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Reverse Tokens Template

Subject: Re: Reverse Tokens Template
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 15 May 2003 20:25:10 +0200
reverse words in a string
Hi Stephen,

This is a really easy task. Using FXSL one would write the following:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:vendor="urn:schemas-microsoft-com:xslt"
 exclude-result-prefixes="vendor"
 >

 <xsl:import href="strSplit-to-Words.xsl"/>

 <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:variable name="vrtfWords">
      <xsl:call-template name="str-split-to-words">
        <xsl:with-param name="pStr" select="/*"/>
        <xsl:with-param name="pDelimiters" select="' ,.;&#9;&#10;'"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:for-each select="vendor:node-set($vrtfWords)/word">
      <xsl:sort select="position()" order="descending" data-type="number"/>
      <xsl:value-of select="."/>
      <xsl:if test="position() != last()">
        <xsl:text> </xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

When applied on this source.xml:

<t>Hello world</t>

the desired result is produced:

world Hello



Hope this helped.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


"Greene, Stephen" <Stephen.Greene@xxxxxx> wrote in message
news:10C94843061E094A98C02EB77CFC32875874D8@xxxxxxxxxxxxxxxxxxxxxxxxx
> 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.