xsl-list
[Top] [All Lists]

RE: Re: Re: Unbounded element grouping/concatenation

2003-12-11 08:52:23
Dimitre, could you help me with a DVC algorithm for what I'm trying
to do? I'm not sure how to apply it to this problem.

I don't have a good idea of what exactly recursive algorithm 
you have to
solve this problem.

It seems to me that such a recursive algorithm would process 
the immediate
following while it is of type="continuation".

The recursive algorithm I wish I could use is exactly as you stated.
Something like the following (not tested, might be typos)

  <xsl:template match="records">
    <xsl:apply-templates select="record[(_at_)type = 'normal']"/>
  </xsl:template>

  <xsl:template match="record[(_at_)type = 'normal']">
    <record>
      <xsl:copy-of select="*" />
      <xsl:if test="following-sibling::record[1][(_at_)type='continuation']">
        <xsl:apply-templates select=following-sibling::record[1]"/>
      </xsl:if>
    </record>
  </xsl:template>

  <xsl:template match="record[(_at_)type = 'continuation']">
    <xsl:copy-of select="*" />
    <xsl:if test="following-sibling::record[1][(_at_)type='continuation']">
      <xsl:apply-templates select=following-sibling::record[1]"/>
    </xsl:if>
  </xsl:template>

However, this gives me a stack overflow error in Xalan (which I'm
stuck with for now). Actually, it gives me a stack overflow in Saxon
too -- I probably need to use named templates or something to get the
tail recursion optimization to work.

To put it in other words, this is not a recursion that processes the
elements of a *known* list, but one that scans a list to find 
a specific
element (in this case record with type="normal").

Exactly. I thought there still might be a way to implement DVC if one
could make the list "known" somehow in some efficient way (keys, or some
other xsl magic).

Often something like binary search can be used to speed up such linear
recursion, but I don't know if this can be used in this specific case.

How would one do this (for a binary search, don't you again need a known
search space?) What information do you need in order to tell me if it can 
be done for this case?

Cheers,
Raman Gupta

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



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