So I'm just starting out with XPathScript.  I have
quite a bit of XSLT experience, and I've noticed a
large difference in style between the two approaches. 
Mty question is basically whether or not I'm
approaching the following problem in the right way for
XPathScript.

I have some XML which uses ID's to form a tree. IE:

<dataset>
  <term>
    <id>2</id>
    <name>molecular_function</name>
    <term2term>
      <term1_id>1</term1_id>
    </term2term>
  </term>
  <term>
    <id>4</id>
    <name>anti-toxin</name>
    <term2term>
      <term1_id>2</term1_id>
    </term2term>
  </term>
</dataset>

Note that term 4 has a value in term2term/term1_id of
2, which is a pointer to it's parent term.  So we have
a tree like this:

term_2:molecular_function
      term_4:anti-toxin

In XSLT, this recursion is handled with a recursive
apply-template.  As far as I can see, there is no way
to do this in XPathScript, so the recursive function
is done in perl:

        <% 
        my @nodes = findnodes('/dataset/term');
        my @node_stack = (1);
        sub node_walker {
                my $parent_node = @node_stack->[scalar(@node_stack)
- 1];
                foreach my $node(@nodes) {
                        if (findvalue('term2term[1]/term1_id', $node) 
                                == $parent_node) {
                                push @node_stack, findvalue('id', $node);
                                print "\n";
                                foreach my $level(@node_stack) {
                                        if ($level ne @node_stack->[0]) {
                                                print '&nbsp;'; 
                                        }
                                }
                                print apply_templates(findnodes('acc', $node));
                                print apply_templates(findnodes('name', $node));
                                &node_walker(findvalue('id', $node));
                        }
                }
                pop @node_stack;
        }
        &node_walker(1);
        %>

Is this the correct XPathScript Approach?  And more
generally, is there any way in XPathScript to
recursively apply_templates?  (maybe recursively is
the wrong term.  The example below should show what I
mean. IE:


        $t->{'term'}{testcode} = 
        sub {
                my $node = shift;
                my $t = shift;
                $t->{'pre'} = "<tr>";

                #  Here's the "recursive" call.
                apply_templates(findnodes('name', $t)); 

                $t->{'post'} = "</tr>";
                return 1;       
        };


Thanks for any comments.

Brad Marshall
Berkeley Drosophila Genome Project

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to