xsl-list
[Top] [All Lists]

Re: to access a particular token in a comma separated string by specifying a numerical value ?

2004-01-26 22:44:57
Use the "str-split-to-words" template from FXSL.

There are numerous examples of using this template in the archives of
xsl-list. See an early example here:

http://sources.redhat.com/ml/xsl-list/2001-11/msg00901.html

In your case this transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:ext="http://exslt.org/common";


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

   <xsl:output indent="yes" omit-xml-declaration="yes"/>

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

when applied on this source.xml:

<t>10, 20,  30,40,   50</t>

produces:

<word>10</word>
<word>20</word>
<word>30</word>
<word>40</word>
<word>50</word>

Note that a delimiter may be anyone from a string of characters -- thus you
could delimit some of your yokens with a coma, with a coma and spaces, with
a semicolon or with whatever you need, and some other tokens with something
else.


Cheers,

Dimitre Novatchev.
FXSL developer,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"SANWAL, ABHISHEK (HP-Houston)" <abhishek(_dot_)sanwal(_at_)hp(_dot_)com> wrote 
in message
news:24B68DDCFD49004882CD8D02D2E4338AFFC043(_at_)cceexc15(_dot_)americas(_dot_)cpqcorp(_dot_)net(_dot_)(_dot_)(_dot_)
How can I access a particular token in a comma separated string by
specifying a numerical value for the token number using XSL?

Assuming, my xsl:variable or xsl:parameter holds a string with
comma-separated values as shown below:

<xsl:variable name="ValuesString" select="'10,20,30,40,50'"/>

How would I go about finding a way to pick out the value specified by a
count that maps another variable/parameter.

Open to Ideas :)
Thanks,

Abhishek
____________________________________________________________

Abhishek Sanwal
HP - Houston Campus

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list