Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - using position() but not in document order >Thread Next - Re: using position() but not in document order Re: using position() but not in document orderTo: NULL Date: 4/7/2008 6:41:00 PM kj wrote: > My question is, will the processor run through every node returned by > the template (i.e., evaluate all three against the if test)? I don't > see why it would stop after the first 2. Am I wrong? In this instance, > it obviously doesn't matter due to the small source file and maybe it > won't ever in my real world uses. > > If I am not wrong about the way the processor would work through the > if test, then is this the best solution? Or is there a better way to > go about it? Well to find the first two elements in sort order the XSLT processor has to sort all nodes. So the <xsl:apply-templates select="a"> <xsl:sort select="@no"/> will process all 'a' elements after sorting them. And that way the <xsl:template match="a"> <xsl:if test="position()<=2"> <xsl:value-of select="."/> </xsl:if> will be applied to all of the sorted 'a' elements. Unless the processor is doing some clever optimization based on the xsl:if that enables it to stop after two elements. Such an optimization is processor specific and you will have to ask an implementor of an XSLT processor whether such things are done. As for other ways to solve that, you could use <xsl:template match="a[position()<=2]"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="a[position() > 2]"/> instead but I am not sure that improves anything in terms of potential optimization. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
