Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Avoid multiple loops

From: AnthonyWJones@-----------.---------.---
To: NULL
Date: 1/5/2006 8:22:00 AM
This may be a better solution.  Rather than having multiple variables for 
each attribute it is probably better to store the Items node that has the 
maximum atrr1 value then the variable holding the node can be queried for the 
other atrr values as and when needed.

Also it's better to move the code to retrieve the maximum atrr1 value to 
it's own template reducing the clutter in the main template.

It's done like this:-

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" encoding="UTF-8" indent="yes" />
	<xsl:template match="/Parent">
		<xsl:variable name="maxAtrr1">
			<xsl:apply-templates select="." mode="getMaxAttr1" />
		</xsl:variable>
		<xsl:variable name="itemsMax" select="Items[@Atrr1=$maxAtrr1]" />
		<result a1="{$itemsMax/@Atrr1}" a2="{$itemsMax/@Atrr2}" 
a3="{$itemsMax/@Atrr3}" a4="{$itemsMax/@Atrr4}" a5="{$itemsMax/@Atrr5}" 
a6="{$itemsMax/@Atrr6}" />
	</xsl:template>
	
	<xsl:template match="Parent" mode="getMaxAttr1">
		<xsl:for-each select="Items">
			<xsl:sort select="@Atrr1" order="descending" data-type="number" />
			<xsl:if test="position()=1">
				<xsl:value-of select="@Atrr1"/>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
</xsl:stylesheet>






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