Re: n squared behavior with XT for 'preceding' tests?

Subject: Re: n squared behavior with XT for 'preceding' tests?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 21 Jul 1999 17:42:14 +0100 (BST)
One thing you can do is work forwards rather than backwards.


Given input of the form

<test>
	<hd>some heading</hd>
...
	<hd>some heading</hd>
	<hd>some OTHER heading</hd>
..
	<hd>some OTHER heading 5555</hd>
</test>

( about 700 lines in my example)

then each of these put out the hd lines, with the first one of each type
flagged by NEWDOC, but the second one appears to run about twice as fast
on an april xt.

==========================================


<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
  result-ns="">

<xsl:template match="hd">	
	<!-- Check to see if the text of the HD matches
		the previous HD's text -->
	<xsl:choose>
	<xsl:when 
	
test="not(text()=from-preceding-siblings(hd[position()=1])/text())">
		<NEWDOC><xsl:copy>
			<xsl:apply-templates/>	  			
			<!-- Output the tag's attributes 
				and its contents -->
		</xsl:copy></NEWDOC>
	</xsl:when>
	<xsl:otherwise>	
		<xsl:copy><xsl:apply-templates/></xsl:copy>
	</xsl:otherwise>	
	</xsl:choose>			
</xsl:template>


</xsl:stylesheet>
==========================================


<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
  result-ns="">

<xsl:template match="test">
<xsl:apply-templates select="hd[1]"/>
</xsl:template>

<xsl:template match="hd">
<xsl:text>
</xsl:text>
		<NEWDOC>
<xsl:copy>
			<xsl:apply-templates/>	  			
			<!-- Output the tag's attributes 
				and its contents -->
		</xsl:copy>
</NEWDOC>
       <xsl:variable name="x" expr="."/>
       <xsl:apply-templates mode="later" select="from-following-siblings(hd[text()=$x])"/>
       <xsl:apply-templates select="from-following-siblings(hd[not(text()=$x)][1])"/>
</xsl:template>

<xsl:template mode="later" match="hd">
<xsl:text>
</xsl:text>
 <xsl:copy> <xsl:apply-templates/></xsl:copy>  			
</xsl:template>


</xsl:stylesheet>
==========================================


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


Current Thread