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

Re: passing intermediate result while recursively buil

Subject: Re: passing intermediate result while recursively building nodeset
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 3 May 2002 22:47:59 +0100
tokenizing a string with javascript
Hi Paul,

> Given a string, I need to create an element to represent each word
> of that string. The created element is relatively complex, and when
> creating the element for word 'i' I may need to go back and examine
> the elements for words 1 thru (i - 1) -- with order being important.
> But at the end of it all, I'll need those newly created elements and
> in the order they were created. Is that of any help? And please, if
> my explanation leaves something to be desired, feel free to ask for
> clarification.

It sounds to me like a two-pass solution would be best here. First
split up the string into words to create a simple node set of 'word'
elements (or something), and then do stuff with that node set to
create the elements that you actually want. That way you only have to
do a result-tree-fragment-to-node-set conversion once, and can
concentrate on each task independently.

You need a simple tokenizing template to split the string into words:
try Dimitre's in the FXSL library, or the one at
http://www.exslt.org/str/functions/tokenize/str.tokenize.xsl if you
want something fairly generic, or roll your own. Then do something
like:

  <xsl:variable name="words">
    <xsl:call-template name="tokenize">
      <xsl:with-param name="string" select="$string" />
    </xsl:call-template>
  </xsl:variable>
  <xsl:apply-templates select="exsl:node-set($words)/*" />

and have a template that matches the 'word' elements you've generated
and does all the stuff (which might involve inspecting the 'word'
element's preceding 'word' siblings).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.