xsl-list
[Top] [All Lists]

Re: [xsl] Create word elements from a string

2009-10-28 17:10:41
You can use the str-split-to-words template of FXSL 1,x

Here is an example of using it:


<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:variable name="vwordNodes">
        <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:variable>

      <xsl:apply-templates select="ext:node-set($vwordNodes)/*"/>
    </xsl:template>

    <xsl:template match="word" priority="10">
      <xsl:value-of select="concat(position(), ' ', ., '&#10;')"/>
    </xsl:template>

</xsl:stylesheet>


When applied on the following XML document:

<t>Use FXSL to do this</t>

the result is:

1 Use
2 FXSL
3 to
4 do
5 this


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Wed, Oct 28, 2009 at 1:44 PM, Larry Hayashi <lhtrees(_at_)gmail(_dot_)com> 
wrote:
Is there a function in XSLT 1.1 that will extract words from a string?
I'd like to be able to take <text>Jill ran up the hill.</text> and get
the following:

<words>
 <word>Jill</word>
 <word>ran</word>
 <word>up</word>
 <word>the</word>
 <word>hill.</word>
</words>

Thanks,
Larry

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>