This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: passing intermediate result while recursively building nodeset


Hi Jeni,

I apologize in the delay in following up on your response (thanks) to my question -- I don't get sick often, but when I do it's a doozy.

I believe I understand your solution, but to my adled brain it appears as if I'm merely substituting a node set for a string, and I'll still confused as to how to access the nodes that I'm creating along the way.

I'm also afraid I've done a poor job of explaining what I'm after, so let me try again ...

Following your suggestion, I take my string (say, "NO BRAIN LEFT") and tokenize it:

    <token>NO</token>
    <token>BRAIN</token>
    <token>LEFT</token>

and then I have a template that matches "token".  Each matching of the "token" template results in the creation of a relatively complex element (say an "x" element).  But to complicate matters, the value of an "x" element can not be *solely* determined by looking at any (or all) of the "token" elements, its value is dependent upon the previously created "x" elements -- that is, when creating the i-th "x" element, I may need to look at the 1 thru (i - 1) "x" elements that were previously created.  In addition, order is important; for example, the "x" element which was created in response to matching "<token>BRAIN</token>" will be the second element in the final node set.


Now, using a suggestion from Michael Kay I can do this, but I was trying to come up with a way that was better than O(n^2) performance.  And I'm not tied to recursion if a technique using "for-each" will do a better job.

Am I making any sense?

Thanks,

Paul
 
--

On Fri, 3 May 2002 22:47:59   
 Jeni Tennison wrote:
>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
>
>



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]