Re: [xsl] passing intermediate result while recursively building nodeset

Subject: Re: [xsl] passing intermediate result while recursively building nodeset
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 3 May 2002 22:47:59 +0100
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 if you
want something fairly generic, or roll your own. Then do something

  <xsl:variable name="words">
    <xsl:call-template name="tokenize">
      <xsl:with-param name="string" select="$string" />
  <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).



Jeni Tennison

 XSL-List info and archive:

Current Thread