Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: using position() but not in document order using position() but not in document orderTo: NULL Date: 4/7/2008 8:59:00 AM I want to do a sort on some nodes and then get the 1st few elements
based on the sort. I have a solution, but I am wondering about
efficiency.
Say I start with this xml:
<practice>
<a no="3">
<b>white</b>
</a>
<a no="2">
<b>red</b>
</a>
<a no="4">
<b>blue</b>
</a>
</practice>
and I want to get the first 2 sorting on @ no ("red white"). So this
works:
<xsl:template match="practice">
<xsl:apply-templates select="a">
<xsl:sort select="@no"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="a">
<xsl:if test="position()<=2">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>
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?
Thanks.
kj
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
