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

Dimitre's algorithm, fixed: quadratic, not exponential

Subject: Dimitre's algorithm, fixed: quadratic, not exponential: Re: HOWTO: convertflat list w/ level
From: David Tolpin <dvd@xxxxxxxxxxxxxx>
Date: Wed, 3 Dec 2003 16:04:57 +0400 (AMT)
xsl exponential
Hello,

thanks to Michael Kay, I have discovered that however expressions in the
Dimitre's algorithm lead to exponential time, they are incorrect. I hope that
this corrected version of Dimitre Novachev's algorithm both produces the
correct result and has quadratic time. The changes are around line the second
following-sibling:: expression.


<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="/node">
    <node>
      <xsl:apply-templates select="node[1]">
        <xsl:with-param name="pParentLevel"
                        select="-1"/>
      </xsl:apply-templates>
    </node>
  </xsl:template>

  <xsl:template match="node">
    <xsl:param name="pParentLevel"/>
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates
       select="following-sibling::node[1]
                       [@level > current()/@level]">
         <xsl:with-param name="pParentLevel" select="@level"/>
       </xsl:apply-templates>
    </xsl:copy>
    <xsl:apply-templates
      select="following-sibling::node
                  [not(@level > current()/@level)]
		  [1]
		  [@level > $pParentLevel]">
      <xsl:with-param name="pParentLevel" select="$pParentLevel"/>
    </xsl:apply-templates>
  </xsl:template>
</xsl:stylesheet>



Sincerely,
David Tolpin

 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.