Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


using position() but not in document order

From: kj <kjulien@---------.--->
To: 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()&lt;=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




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent